快排
来源:互联网 发布:水果音乐制作软件 编辑:程序博客网 时间:2024/06/09 13:38
#include<iostream>using namespace std;long e;long a[100000];void qsort(int l,int r){ int i,j; long t; i=l; j=r; t=a[i]; do{ while(a[j]>t) j--; while(a[i]<t) i++; if(i<=j){ e=a[j]; a[j]=a[i]; a[i]=e; i++; j--; } }while(i<=j); if(l<j) qsort(l,j); if(i<r) qsort(i,r);}int main(){ int n; cin>>n; for(int i=0;i<n;i++) cin>>a[i]; qsort(0,n-1); for(int i=0;i<n;i++) cout<<a[i]<<' '; return 1;}