Created
October 17, 2013 10:22
-
-
Save sverrejoh/7022556 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void quicksort(int l, int u) | |
{ int i, m; | |
// Return if length is 0 | |
if (l >= u) { | |
return; | |
} | |
// Move random element to start | |
swap(l, randint(l, u)); | |
m = l; | |
// Iterate all element after start | |
for (i = l+1; i <= u; i++) | |
// if element is smaller than pivot, move it to the first section. | |
if (x[i] < x[l]) { | |
swap(++m, i); | |
} | |
// Swap pivot into last, which is smaller an can then be at beginning. | |
swap(l, m); | |
quicksort(l, m-1); | |
quicksort(m+1, u); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment