We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5d7cd75 commit ec78dc5Copy full SHA for ec78dc5
sort/insertion_sort.c
@@ -0,0 +1,31 @@
1
+// INSERTION SORT
2
+
3
+#include<stdio.h>
4
5
+int main(){
6
7
+ int i,j,s,temp,a[20];
8
9
+ printf("Enter total elements: ");
10
+ scanf("%d",&s);
11
12
+ printf("Enter %d elements: ",s);
13
+ for(i=0;i<s;i++)
14
+ scanf("%d",&a[i]);
15
16
+ for(i=1;i<s;i++){
17
+ temp=a[i];
18
+ j=i-1;
19
+ while((temp<a[j])&&(j>=0)){
20
+ a[j+1]=a[j];
21
+ j=j-1;
22
+ }
23
+ a[j+1]=temp;
24
25
26
+ printf("After sorting: ");
27
28
+ printf(" %d",a[i]);
29
30
+ return 0;
31
+}
0 commit comments