#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
const int M = 1000000;
int r[M];
int partition (int *r,int low,int high) //返回中间元素的位置,函数做到将序列分成左右两部分
{
int i = low, j = high, privot = r[low];//这里注意,privot是一个数值,而不是数组下标!!!
while(i<j)
{
while(i<j&&r[j]>privot)
j--;
if(i<j&&r[j]<privot)
{
swap(r[i],r[j]);
i++; //为什么是i++呢?因为现在指向privot的是j
}
while(i<j&&r[i]<=privot)
i++;
if(i<j&&r[i]>=privot)
{
swap(r[i],r[j]);
j--; //同理,经过交换后现在指向privot的是i
}
}
return i;
}
void QuickSort(int *r, int low, int high)
{
if(low<high)
{
int mid = partition(r,low,high);
QuickSort(r, low, mid-1);
QuickSort(r, mid+1, high);
}
}
int main()
{
int n;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>r[i];
}
QuickSort(r,0,n-1);
cout<<"排好序之后是:"<<endl;
for(int i=0;i<n;i++)
{
cout<<r[i]<<" ";
}
return 0;
}