#include<iostream> #include<cstdio> using namespace std; int a[100001]={0}; int dg_sort(int l,int r){ int mid=a[(l+r)/2]; int i=l,j=r; while(i<=j){ while(a[i]<mid) i++; while(a[j]>mid) j--; if(i<=j){ swap(a[i],a[j]); i++; j--; } } if(l<j) dg_sort(l,j); if(r>i) dg_sort(i,r); } int main(){ int n; cin>>n; for(int i=1;i<=n;i++) scanf("%d",&a[i]); dg_sort(1,n); for(int i=1;i<=n;i++) printf("%d ",a[i]); }
原文:https://www.cnblogs.com/latent-Lin/p/15125995.html