这里写自定义目录标题
#include<bits/stdc++.h>
using namespace std;
const int N=1e6;
int a[N];
void quick_sort(int left,int right)//函数列(核心!!!)
{
int i,j,temp;
if(left>=right) return;
i=left;j=right;temp=a[left];
while(i!=j)
{
while(j>i)
{
j--;
if(a[j]<temp) break;
}
while(i<j)
{
i++;
if(a[i]>temp) break;
}
int x;
x=a[i];
a[i]=a[j];
a[j]=x;
}
swap(a[i],a[left]);
quick_sort(left,i-1);quick_sort(i+1,right);//注意两边边界
}
int main()
{
int n;
cin>>n;
for(int i=0;i<n;i++)
cin>>a[i];
quick_sort(0,n-1);
for(int i=0;i<n;i++)
cout<<a[i]<<" ";
}
详细请看