理想O(n log n)最差O(n^2)快速排序:首先任意选取一个数据,然后将所有比它小的数都放到它前面,所有比它大的数都放到它后面,这是一趟快速排序。var i,j,n:longint; a:array[1..1000000] of longint;PRocedure qsort(l,r:longint);var m,t:longint;begin i:=l;j:=r; m:=a[(l+r) div 2]; repeat while a[i]<m do inc(i); while a[j]>m do dec(j); if i<=j then begin t:=a[i]; a[i]:=a[j]; a[j]:=t; inc(i); dec(j); end; until i>j; if l<j then qsort(l,j); if i<r then qsort(i,r);end;begin readln(n); for i:=1 to n do read(a[i]); qsort(1,n); for i:=1 to n do write(a[i],' ');end.