Created
March 16, 2018 15:37
-
-
Save Dimanaux/61400832fbc7805524d9bf334667e608 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 Sort { | |
public static void sort(Integer[] array) { | |
quickSort(array, 0, array.length); | |
} | |
private static void quickSort(Integer[] array, int begin, int end) { | |
if (begin < end) { | |
int p = partition(array, begin, end); | |
quickSort(array, begin, p); | |
quickSort(array, p, end); | |
} | |
} | |
private static int partition(Integer[] array, int begin, int end) { | |
int pivot = array[begin]; | |
int i = begin; | |
int j = end - 1; | |
while (true) { | |
while (array[i] < pivot) { | |
i++; | |
} | |
while (array[j] > pivot) { | |
j--; | |
} | |
if (i >= j) { | |
return j; | |
} | |
// swap(array[i], array[j]); | |
int t = array[i]; | |
array[i] = array[j]; | |
array[j] = t; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment