-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbubbleSort.c
More file actions
38 lines (31 loc) · 777 Bytes
/
bubbleSort.c
File metadata and controls
38 lines (31 loc) · 777 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
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
void printArr(int *arr,int size){
for(int i = 0 ; i < size ; i ++)
printf("%d ",arr[i]);
}
void swap(int *a ,int *b){
int temp = *a ;
*a = *b;
*b = temp;
}
int main(){
int size;
scanf("%d",&size);
int *arr = (int *)malloc(size*sizeof(int));
for (int i = 0; i < size; i++) {
scanf("%d", &arr[i]);
}
time_t start = clock();
for(int i = 0 ; i < size -1 ; i ++){
for(int j = 0; j < size - i -1 ; j++){
if(arr[j+1] < arr[j]){
swap(&arr[j+1],&arr[j]);
}
}
}
time_t end = clock();
printf("%.10f",(double)(end-start)/CLOCKS_PER_SEC);
return 0 ;
}