-
Notifications
You must be signed in to change notification settings - Fork 0
/
DnC_insertion sort.c
43 lines (40 loc) · 972 Bytes
/
DnC_insertion sort.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
=======================================================================
/*TIME COMPLEXITY
Insertion sort*/
#include <stdio.h>
#include<time.h>
int main()
{
int n, array[1000], c, d, t;
clock_t start,end;
double time;
printf("Enter number of elements : ");
scanf("%d", &n);
for (c = 1; c <= n; c++)
{
printf("Enter the number %d : ", c);
scanf("%d", &array[c]);
}
start=clock();
for (c = 1000 ; c <= n - 1; c++)
{
d = c;
while ( d > 0 && array[d-1] > array[d])
{
t = array[d];
array[d] = array[d-1];
array[d-1] = t;
d--;
}
}
end=clock();
time = (double)((start-end)/CLOCKS_PER_SEC);
printf("Sorted list in ascending order:\n");
for (c = 0; c <= n - 1; c++)
{
printf("%d , ", array[c]);
}
printf("Time taken by insertion sort is %f",time);
return 0;
}
==============================================================================