Implement a quickerSort
method
This commit is contained in:
parent
3390369d0e
commit
0ad3397ad0
|
@ -79,11 +79,36 @@ public class SortServer implements CommandExecutor {
|
|||
|
||||
private void quickerSort(int[] arr, int left, int right) {
|
||||
// To do Aufgabe 12.1
|
||||
if (right - left < insertion_threshold) {
|
||||
insertionSort(arr, left, right);
|
||||
} else {
|
||||
int l = partition(arr, left, right);
|
||||
quickerSort(arr, left, l - 1);
|
||||
quickerSort(arr, l, right);
|
||||
}
|
||||
}
|
||||
|
||||
private int partition (int[] arr, int left, int right) {
|
||||
// To do Aufgabe 12.1
|
||||
return 0;
|
||||
int pivot = arr[(left + right) / 2];
|
||||
|
||||
while (left <= right) {
|
||||
while (arr[left] < pivot) {
|
||||
left++;
|
||||
}
|
||||
|
||||
while (arr[right] > pivot) {
|
||||
right--;
|
||||
}
|
||||
|
||||
if (left <= right) {
|
||||
swap(arr, left, right);
|
||||
left++;
|
||||
right--;
|
||||
}
|
||||
}
|
||||
|
||||
return left;
|
||||
}
|
||||
|
||||
private boolean isSorted(int[] a) {
|
||||
|
|
Loading…
Reference in a new issue