Skip to content

Instantly share code, notes, and snippets.

@Dimanaux
Created March 16, 2018 15:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dimanaux/61400832fbc7805524d9bf334667e608 to your computer and use it in GitHub Desktop.
Save Dimanaux/61400832fbc7805524d9bf334667e608 to your computer and use it in GitHub Desktop.
смейтесь, смейтесь!
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