-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbubble_sort.c
More file actions
65 lines (52 loc) · 773 Bytes
/
bubble_sort.c
File metadata and controls
65 lines (52 loc) · 773 Bytes
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
#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;
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 ");
dec=len;
n=0;
// applying bubble sort
//
while(dec!=0){
for(n;n<len;n++)
{
if(arr[n] > arr[n+1])
{
swap=arr[n+1];
arr[n+1]=arr[n];
arr[n]=swap;
}
}
dec--;
n=0;
}
n=0;
printf("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);
}