Skip to content

Instantly share code, notes, and snippets.

@ayberk
Created April 24, 2014 20:25
Show Gist options
  • Save ayberk/11268362 to your computer and use it in GitHub Desktop.
Save ayberk/11268362 to your computer and use it in GitHub Desktop.
private static void threeWayQuickSort(int[] a, int lo, int hi)
{
if (hi <= lo) return;
int i = lo;
int lessThan = lo;
int greaterThan = hi;
int pivot = a[lo];
while (i <= greaterThan)
{
if (a[i] < pivot) {
swap(a, lessThan++, i);
} else if (a[i] > pivot) {
swap(a, greaterThan--, i);
} else {
i++;
}
}
threeWayQuickSort(a, lo, lessThan);
threeWayQuickSort(a, greaterThan+1, hi);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment