您的位置:首页 > 其它

随机快速排序

2009-10-12 20:25 120 查看

#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);


}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: