Skip to content

Commit

Permalink
Merge pull request TheAlgorithms#17 from theycallmemac/patch-6
Browse files Browse the repository at this point in the history
Rename InsertionSort.c to Sorts/InsertionSort.c
  • Loading branch information
r0hit-gupta authored Aug 8, 2017
2 parents 47c45d0 + ff15058 commit 6d67344
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions Sorts/InsertionSort.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <stdio.h>
#incude <stdlib.h>
#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;
}

0 comments on commit 6d67344

Please sign in to comment.