Created
March 14, 2015 23:14
-
-
Save frydaykg/d17444463e4427ab882a to your computer and use it in GitHub Desktop.
Lamuto partition improved
This file contains hidden or 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
| int Partition(int *a, int l, int r) { | |
| r--; | |
| int pivot = a[r]; | |
| int i = l - 1; | |
| for (int j = l; j < r; j++) | |
| if (a[j] <= pivot) | |
| if (++i != j) | |
| swap(a[i], a[j]); | |
| swap(a[++i], a[r]); | |
| return i; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment