首页 > 编程语言 > 详细

快速排序

时间:2015-04-05 23:17:51      阅读:297      评论:0      收藏:0      [点我收藏+]
void temp(int *l,int i,int j){
    int t=l[i];
    l[i]=l[j];
    l[j]=t;        
}
int partition(int *l,int low,int high){
    int privotkey=l[low];
    while(low<high){
        while(low<high&&l[high]>=privotkey)
            high--;
        temp(l,low,high);
        while(low<high&&l[low]<=privotkey)
            low++;
        temp(l,low,high);    
    }
return low;
}
void Qsort(int *L,int low,int high){
int privot;
if(low<high){

privot=partition(L,low,high);

Qsort(L,low,privot-1);
Qsort(L,privot+1,high);
}
}
void QuickSort(int *a,int length){
Qsort(a,1,length);

}

 

快速排序

原文:http://www.cnblogs.com/qiaomu/p/4394953.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!