#include<iostream>
using namespace std;
int a[100000];
int i,j;
int par(int r[],int first,int end)
{
i=first,j=end;
r[0]=r[i];
while(i<j)
{
while(i<j&&r[0]<=r[j]) j--;
if(i<j){
r[i]=r[j];i++;
}
while(i<j&&r[i]<=r[0]) i++;
if(i<j) {r[j]=r[i];j--;}
}
r[i]=r[0];
return i;
}
int pos;
void quickSort(int r[],int first,int end)
{
if(first<end){
pos=par(r,first,end);
quickSort(r,first,pos-1);
quickSort(r,pos+1,end);}
}
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i];
quickSort(a,1,n);
for(int i=1;i<=n;i++) cout<<a[i]<<" ";
}
来源:CSDN
作者:狠人王
链接:https://blog.csdn.net/weixin_43238423/article/details/103573643