Created
April 24, 2014 20:25
-
-
Save ayberk/11268362 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
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