快速排序

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

}

 

posted @ 2015-04-05 22:40  ~每天进步一点点~  阅读(152)  评论(0编辑  收藏  举报