Skip to content

Commit 832c1e7

Browse files
authored
Merge pull request deutranium#156 from mashiyathussain2/patch-2
Create InsertionSort.c
2 parents bc32952 + 1553c03 commit 832c1e7

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include <stdio.h>
2+
3+
void main()
4+
{
5+
int n,array[1000],c,d,t;
6+
7+
printf("Enter number of elements\n");
8+
scanf("%d", &n);
9+
10+
printf("Enter %dintegers\n",n);
11+
12+
for(c=0;c<n;c++)
13+
scanf("%d",&array[c]);
14+
15+
for(c=1;c<=n-1;c++) {
16+
d=c;
17+
18+
while(d>0 &&array[d-1]>array[d]) {
19+
t = array[d];
20+
array[d] = array[d-1];
21+
array[d-1] = t;
22+
d--;
23+
}
24+
}
25+
printf("Sorted list in ascending order:\n");
26+
for(c=0;c<n-1;c++){
27+
printf("%d\n",array[c]);
28+
}
29+
getch();
30+
}

0 commit comments

Comments
 (0)