Quick Sort Qsort quicksort C language

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.