1 #include <stdio.h>
2 #include<time.h>
3 #define MAX 50000
4 #define RANDOM(x) (rand()%x)
5 swap(int *a,int *b)
6 {
7 int temp;
8 temp=*a;
9 *a=*b;
10 *b=temp;
11 }
12 quick_sort(int *arr,int start,int end)
13 {
14 int i;
15
16 if(end>=start+1)
17 {
18 int left=start+1,right=end,base=start;
19 while(left<right)
20 {
21 if(arr[left]>arr[base])
22 {
23 swap(&arr[left],&arr[right]);
24 right--;
25 }
26 else
27 {
28 left++;
29 }
30 }
31 if(arr[left]<arr[base])
32 {
33 swap(&arr[left],&arr[base]);
34 quick_sort(arr,start,--left);
35 quick_sort(arr,left,end);
36 }
37 else {
38 if (end - start == 1) return;
39 swap(&arr[left],&arr[base]);
40 quick_sort(arr, start,--left);
41 quick_sort(arr, left,end);
42 }
43 }
44 }
45 int main()
46 {
47 int i=0,arr[MAX];
48 srand(time(0));
49 for(i=0;i<MAX;i++)
50 {
51 arr[i]=RANDOM(100);
52 printf("%d\t",arr[i]);
53 }
54 quick_sort(arr,0,MAX-1);
55 printf("\n");
56 for(i=0;i<MAX;i++)
57 printf("%d\t",arr[i]);
58 }