Skip to content

Instantly share code, notes, and snippets.

@rehrumesh
Created April 17, 2015 05:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rehrumesh/62421bf7c9028b237362 to your computer and use it in GitHub Desktop.
Save rehrumesh/62421bf7c9028b237362 to your computer and use it in GitHub Desktop.
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