Skip to content

Instantly share code, notes, and snippets.

@frydaykg
Created March 14, 2015 23:14
Lamuto partition improved
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