#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
#include<map>


using namespace std;


int partition(vector<int> &A, int begin,int end){
    int cmpVal = A[end];
    int i = begin-1;

    for(int j = begin; j < end; j++){
        if(A[j] < cmpVal){
            i++;
            swap(A[i],A[j]);
        }
    }
    swap(A[end],A[i+1]);

    return i+1;
}
void quickSort(vector<int> &A, int begin,int end) {
    if(begin < end){
        int mid = partition(A,begin,end);
        quickSort(A,begin,mid-1);
        quickSort(A,mid+1,end);
    }
}

int main(){
    vector<int> a = {7,5,6,4,9,3,4,6,1};
    quickSort(a,0,a.size()-1);
    for(int i = 0; i < a.size();i++){
        cout<<a[i]<<" ";
    }
    return 0;
}

   

posted on 2019-12-17 22:29  笨宝宝  阅读(131)  评论(0编辑  收藏  举报