forked from Biswajitghosh98/algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
insert1.c
46 lines (42 loc) · 803 Bytes
/
insert1.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <assert.h>
void insertionSort(int ar_size, int * ar)
{
int i,j,k,flag =0;
for(k = ar_size-1;k>=0;k--)
{
int e = ar[k];
for(i=ar_size-1;i>=0;i--)
{
if(ar[i-1]>=e)
{
ar[i] = ar[i-1];
}
else
{
ar[i] = e;
flag = 1;
}
if(flag == 1)
break;
}
for(j=0;j<ar_size;j++)
{
printf("%d ",ar[j]);
}
printf("\n");
}
}
int main(void) {
int _ar_size;
scanf("%d", &_ar_size);
int _ar[_ar_size], _ar_i;
for(_ar_i = 0; _ar_i < _ar_size; _ar_i++) {
scanf("%d", &_ar[_ar_i]);
}
insertionSort(_ar_size, _ar);
return 0;
}