Skip to content

Commit 4636f91

Browse files
authored
Create Insertionsort.c
1 parent cf5c406 commit 4636f91

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

Insertionsort.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include<stdio.h>
2+
#include<stdlib.h>
3+
4+
5+
void InsertionSort(int A[],int n)
6+
{
7+
int i,j,x;
8+
for (i=1;i<n;i++)
9+
{
10+
j=i-1;
11+
x = A[i];
12+
while(j>-1 && A[j]>x)
13+
{
14+
A[j+1] = A[j];
15+
j--;
16+
}
17+
A[j+1] = x;
18+
}
19+
}
20+
21+
22+
int main()
23+
{
24+
int A[10] = {1,5,2,1,6,3,6,2,5,10};
25+
int i;
26+
InsertionSort(A,10);
27+
for(i=0;i<10;i++)
28+
{
29+
printf("%d ",A[i]);
30+
}
31+
return 0;
32+
}

0 commit comments

Comments
 (0)