-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathquickSort.c
More file actions
55 lines (46 loc) · 993 Bytes
/
quickSort.c
File metadata and controls
55 lines (46 loc) · 993 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
#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 Partition(int *arr,int l,int r){
int s = l;
int i = 0;
int pivot = arr[l];
for(i = l+1; i <= r;i++){
if(arr[i] < pivot){
s++;
swap(&arr[i],&arr[s]);
}
}
swap(&arr[l],&arr[s]);
return s;
}
void QuickSort(int *arr, int l ,int r){
if(l<r){
int s = Partition(arr,l,r);
QuickSort(arr,l,s-1);
QuickSort(arr,s+1,r);
}
}
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();
QuickSort(arr,0,size-1);
time_t end = clock();
printf("%.10f",(double)(end-start)/CLOCKS_PER_SEC);
return 0;
}