#include <bits/stdc++.h> using namespace std; void ksort(int *a,int l,int r){ int mid = a[(l+r)/2]; int i = l,j = r; do{ while(a[i]<mid){ i++; } while(a[j]>mid){ j--; } if(i<=j){ swap(a[i],a[j]); i++; j--; } }while(i<=j); if(l<j){ ksort(a,l,j); } if(i<r){ ksort(a,i,r); } } int main(){ int n; cin>>n; int a[n+5]; for(int i = 1;i<=n;i++){ cin>>a[i]; } ksort(a ,1,n); for(int i = 1;i<=n;i++){ cout<<a[i]<<endl; } return 0; }
标签:std,do,int,mid,ksort,排序,快速 From: https://www.cnblogs.com/wangyihang-xh/p/18097688