Now the online search of the fast row and I played before the same, feeling a bit complicated, I used the freepascal/demo/text/qsort.pp style, feeling particularly concise.
1#include <stdio.h>2 #defineMAXN 100003 intA[MAXN];4 intN;5 voidMysort (intLintr) {6 intx,y,mid,t;7Mid = a[(l+r)/2];8x=l;9y=R;Ten Do { One while(a[x]<mid) x + +; A while(A[y]>mid) y--; - if(x<=y) { -t=A[x]; thea[x]=A[y]; -a[y]=T; -X + +; -y--; + } -} while(x<=y); + if(l<y) Mysort (l,y); A if(x<R) Mysort (x,r); at } - intMain () { - inti; -scanf"%d",&n); - for(i=0; i<n; i++) { -scanf"%d",&a[i]); in } -Mysort (0, N-1); to for(i=0; i<n; i++) printf ("%d", A[i]); + return 0; -}
(where (x+y)/2 can be written (x+y) >>1 lifting Speed
(For an intern interview recently, review the basic algorithm.) Before the sort of basic use of STL's sort, and quickly forget, I didn't think I was going to hit it out again the clam hafnium ha
Quick Sort Qsort quicksort C language