#include "stdio.h"
#include "stdlib.h"
#include "time.h"
#include "math.h"
#define N 50000
void quickSort(int a[],int left,int right)
{
int i,j,temp;
i=left;
j=right;
temp=a[left];
if(left>right)
return;
while(i!=j)
{
while(a[j]>=temp &&
j>i)
j--;
if(j>i)
a[i++]=a[j];
while(a[i]<=temp &&
j>i)
i++;
if(j>i)
a[j--]=a[i];
}
a[i]=temp;
quickSort(a,left,i-1);
quickSort(a,i+1,right);
}
int main()
{
double
t2=clock();
int
i,a[N];
for(i=0;i
{
a[i]=rand()%N;
}
quickSort(a,0,N-1);
t2=clock()-t2;
for(i=0;i
{
printf("M\n",a[i]);
}
printf("\n快速排序%d个随机数字所用时间为:%f毫秒\n",N,(double)t2);
return
1;
}
32746
32747
32747
32748
32748
32749
32749
32751
32751
32751
32751
32754
32756
32756
32757
32759
32759
32759
32759
32760
32760
32762
32762
32763
32763
32764
32764
32764
32765
32766
快速排序50000个随机数字所用时间为:15.000000毫秒
Press any key to continue