//
// quicksort.cpp
// leecode
//
// Created by 陆炫宇 on 17/3/9.
// Copyright © 2017年 陆炫宇. All rights reserved.
//
#include <iostream>
#include<time.h>
using namespace std;
void exXchange(int *a,int p,int q){
int temp=a[p];
a[p]=a[q];
a[q]=temp;
}
int quicksort(int *a,int be,int ed){
int x=a[be];
int p=be,j=be+1;
while(j<ed+1){
if(a[j]>x){
j++;
}
else{
exXchange(a,p+1,j);
p++;
j++;
}
}
exXchange(a,be,p);
return p;
}
void partition(int *a,int be,int ed){
if(be<ed){
srand((unsigned)time(NULL));
int r=(int)rand()%(ed-be+1)+be;
exXchange(a,0,r);
int p=quicksort(a,be,ed);
partition(a,be,p-1);
partition(a,p+1,ed);
}
}
int main(){
int a[]={3,4,5,1,2};
partition(a,0,4);
for(int i=0;i<5;i++)
cout<<a[i];
cout<<endl;
return 0;
}