mirror of
https://github.com/TheAlgorithms/C
synced 2024-11-22 13:31:21 +03:00
Merge pull request #8 from malnuxstarck/patch-3
Add insertion sort method
This commit is contained in:
commit
4ba0907497
29
InsertionSort.c
Normal file
29
InsertionSort.c
Normal file
@ -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;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user