Skip to content

Instantly share code, notes, and snippets.

@frydaykg
Created March 14, 2015 23:15
Show Gist options
  • Select an option

  • Save frydaykg/63d84462a327c1b21d26 to your computer and use it in GitHub Desktop.

Select an option

Save frydaykg/63d84462a327c1b21d26 to your computer and use it in GitHub Desktop.
Hoare partition
int Partition(int *a, int l, int r) {
int x = a[l], i = l - 1, j = r;
while (1) {
do j--; while (a[j] > x);
do i++; while (a[i] < x);
if (i < j)
swap(a[i],a[j]);
else
return j + 1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment