-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSort-Three-Way Quicksort.c
More file actions
45 lines (35 loc) · 1.11 KB
/
Sort-Three-Way Quicksort.c
File metadata and controls
45 lines (35 loc) · 1.11 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
/*
Program: Three-Way Quicksort
Author name: Mohamed Jasim Pocha
Email: mohd.jas@gmail.com
Created: 2013-12-13
Last modified:
*/
#include "sorthelper.c"
void quicksort_3way(int *array, int low, int high)
{
register i = low, lt = low, gt = high, p = array[low];
if (low >= high) return;
while (i <= gt)
{
if (array[i] < p) { exch(array, i++, lt++); }
if (array[i] > p) { exch(array, i, gt--); }
if (array[i] == p) { i++; }
}
quicksort_3way(array, low, lt-1);
quicksort_3way(array, gt+1, high);
}
int main (int argc, char *argv[])
{
ARRAY_SIZE = atoi(argv[1]);
int array[ARRAY_SIZE];
init_array(array);
clock_t start, end;
double cpu_time_used;
start = clock();
quicksort_3way(array, 0, ARRAY_SIZE-1);
end = clock();
cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
printf("%f\n", cpu_time_used);
return 0;
}