-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselection_sort.c
More file actions
79 lines (60 loc) · 1.23 KB
/
selection_sort.c
File metadata and controls
79 lines (60 loc) · 1.23 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include<stdio.h>
#include <time.h>
int main()
{
clock_t start, end;
double cpu_time_used;
start = clock();
int n=0;
int arr[100];
int len;
int swap;
int dec;
int new_vr;
int a,b;
printf("enter length of array and data in array ");
scanf("%d",&len);
for(n;n<len;n++)
{
scanf("%d",&arr[n]);
}
n=0;
printf("array is \n ");
for(n;n<len;n++)
{
printf("%d ",arr[n]);
}
printf(" \n ");
n=0;
// applying selection sort
while(n<len)
{
a=n+1;
printf(" \n a== %d ",a);
b=arr[n];
printf(" \n b== %d ",b);
for(a;a<=len;a++)
{printf(" \n a_inside == %d ",a);
printf(" \n b_inside == %d ",b);
if(b > arr[a])
{
b = arr[a];
printf(" \n b value = %d ",b);
}
swap=arr[n];
arr[n]=b;
b=swap;
n++;
}
printf(" \n n== %d ",n);
}
n=0;
printf("\n new array is \n ");
for(n;n<len;n++)
{
printf("%d ",arr[n]);
}
end = clock();
cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
printf("time used is %f",cpu_time_used);
}