Created
April 17, 2015 05:29
-
-
Save rehrumesh/62421bf7c9028b237362 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
public static void quickSort(int array[]) { | |
quickSort(array, 0, array.length - 1); | |
} | |
public static void quickSort(int array[], int start, int end) { | |
int i = start; | |
int k = end; | |
if (end - start >= 1) { | |
int pivot = array[start]; | |
while (k > i) { | |
while (array[i] <= pivot && i <= end && k > i) { | |
i++; | |
} | |
while (array[k] > pivot && k >= start && k >= i) { | |
k--; | |
} | |
if (k > i) { | |
swap(array, i, k); | |
} | |
} | |
swap(array, start, k); | |
quickSort(array, start, k - 1); | |
quickSort(array, k + 1, end); | |
} else { | |
return; | |
} | |
} | |
public static void swap(int array[], int index1, int index2) { | |
int temp = array[index1]; | |
array[index1] = array[index2]; | |
array[index2] = temp; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment