Created
May 10, 2018 04:05
-
-
Save kbrx93/c44af7420d55daa8483bf4138d516ab1 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 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