Skip to content

Instantly share code, notes, and snippets.

@kbrx93
Created May 10, 2018 04:05
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 kbrx93/c44af7420d55daa8483bf4138d516ab1 to your computer and use it in GitHub Desktop.
Save kbrx93/c44af7420d55daa8483bf4138d516ab1 to your computer and use it in GitHub Desktop.
public class MyQuickSort {
public static void quickSort(int[] arr, int low, int high) {
if (arr == null || arr.length <= 1 || low >= high)
return;
int i = low;
int j = high;
int midInArray = arr[(low + high) / 2];
while (i <= j) {
while (arr[i] < midInArray)
++i;
while (arr[j] > midInArray)
--j;
if (i < j) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = arr[i];
++i;
--j;
} else if (i == j){
++i;
}
}
quickSort(arr, low, j);
quickSort(arr, i, high);
}
public static void main(String[] args){
int[] array = new int[]{1, 3, 2};
quickSort(array, 0, array.length - 1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment