#include<bits/stdc++.h>
using namespace std;
int a[1010];
void partitiontest(int a[],int start,int end)
{
if(start>=end)return;
//意思是选定一个基准值(第一个数),大于它的放右边,小于它的放左边,这个是快拍的精髓
int low=start;
int high=end;
int index=a[low];
while(low<high)
{
while(high>low&&a[high]>index)
{
high--;
}
if(high>low)
{
a[low++]=a[high];
}
while(high>low&&a[low]<index)
{
low++;
}
if(high>low)
{
a[high--]=a[low];
}
}
a[low]=index;
//此步骤很重要,分而治之
partitiontest(a,start,low-1);
partitiontest(a,low+1,end);
}
int main()
{
int a[1010];
cout<<"请输入数组个数"<<endl;
int num=0;
cin>>num;
cout<<"请输入:"<<endl;
for(int i=0;i<num;i++)
{
cin>>a[i];
}
partitiontest(a,0,num);
for(int i=0;i<num;i++)
{
cout<<a[i]<<" ";
}
return 0;
}