码迷,mamicode.com
首页 > 编程语言 > 详细

快速排序

时间:2015-04-05 23:17:59      阅读:211      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!