Quick sort

C++:
01 void quicksort(int A[], int l, int u)
02 {
03   int i, m;
04   if(l>=u) return;
05   swap(A, l, randint(l,u));
06   m=l;
07   for(i=l+1;i<=u;i++)
08     if(A[i]<A[l])
09       swap(A,++m,i);
10   swap(A,l,m);
11   quicksort(l,m1);
12   quicksort(m+1,u);
13 }
Advertisements
This entry was posted in Divide and Conquer. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s