QuickSort

#include<iostream>
using namespace std;
void QuickSort(int a[],int low,int high);
int partition(int a[],int low,int high);
void QuickSort(int a[],int low,int high){
     if(low<high){
         int piovt=partition(a,low,high);
         QuickSort(a,low,piovt-1);
         QuickSort(a,piovt+1,high);
     }
}
int partition(int a[],int low,int high){
    int pivot;
    pivot = a[low];
    while(low<high){
        while(low<high&&a[high]>=pivot)high--;
        if(low<high) a[low++]=a[high];
        while(low<high&&a[low]<=pivot) low++;
        if(low<high) a[high--]=a[low];
    }
    a[low]=pivot;
    return low;
}
int main(){
    int a[]={6,5,4,4,3,2,3,2,1,43,34,34,243,32,32,32,234,243,43,43,4,3,32,32,32,0,32,3,32,32,2,23,2,2,32,0,32,32,23};
    int len=sizeof(a)/sizeof(int);
    QuickSort(a,0,len-1);
    for(int i=0;i<len;i++)
        cout << a[i] << ",";
    system("pause");
    return 0;
    }

你可能感兴趣的:(QuickSort)