From 953d87a21ca3a8228a9b8557791223c9edbd528a Mon Sep 17 00:00:00 2001 From: Abdoul Malik Date: Thu, 23 Mar 2017 15:15:17 +0100 Subject: [PATCH] Add insertion sort method --- InsertionSort.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 InsertionSort.c diff --git a/InsertionSort.c b/InsertionSort.c new file mode 100644 index 00000000..4f3e749e --- /dev/null +++ b/InsertionSort.c @@ -0,0 +1,29 @@ +#include +#incude +#define MAX 20 + + + +int main() +{ + int i, elmtToInsert , j , arraySort[MAX] = {0}; + + for(i = 1 ; i < MAX ; i++) + { + elmtToInsert = arraySort[i]; + j = i - 1 ; + + while( j >= 0 && elmtToInsert < arraySort[j]) + { + arraySort[j+1] = arraySort[j]; + j--; + } + + arraySort[j+1] = elmtToInsert ; + } + + + + + return EXIT_SUCCESS; +}