当年抓破头皮没想出来,溜了一眼算法导论豁然开朗。其实就是排以前交换一下pivot。 #include <stdlib.h> #include <time.h>#include <stdio.h>typedef int Record; void QuickSort (Record r[],int s,int t);void QuickSort (Record r[],int s,int t)...{ int low=s; int high=t; Record pivot; ...{ int t,tn; srand(time(NULL)); tn=rand()%(high-low+1)+low; t=r[low]; r[low]=r[tn]; r[tn]=t; } pivot=r[s]; while (low<high)...{ while (low<high && r[high]>pivot) high--; if (low<high) r[low++]=r[high]; while (low<high && r[low]<pivot) low++; if (low<high) r[high--]=r[low]; } r[low]=pivot; if (s<low) QuickSort(r,s,low-1); if (t>high) QuickSort(r,high+1,t);}