-
Notifications
You must be signed in to change notification settings - Fork 0
/
quick_sort.c
53 lines (46 loc) · 1.15 KB
/
quick_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
44
45
46
47
48
49
50
51
52
53
// write a programme to implement quick sort
#include<stdio.h>
#include<time.h>
#define num 10000
void quicksort(int list[], int low,int high){
int pivot, i, j, temp;
if (low < high)
{
pivot = low;
i = low;
j = high;
while (i < j)
{
while (list[i] <= list[pivot] && i <= high)
{
i++;
}
while (list[j] > list[pivot] && j >= low)
{
j--;
}
if (i < j)
{
temp = list[i];
list[i] = list[j];
list[j] = temp;
}
}
temp = list[j];
list[j] = list[pivot];
list[pivot] = temp;
quicksort(list, low, j - 1);
quicksort(list, j + 1, high);
}}
void main(){
int list[num],i;
clock_t startt,endt;
double totalt;
for(i=0;i<num;i++){
scanf("%d", &list[i]);}
startt=clock();
quicksort(list, 0, num-1);
endt=clock();
totalt=((double)(endt-startt)/CLOCKS_PER_SEC);
printf("THE TIME TAKEN IS%lf",totalt);
}