diff --git a/app/src/main/java/ch/nuth/zhaw/exbox/SortServer.java b/app/src/main/java/ch/nuth/zhaw/exbox/SortServer.java index ffbd647..fb95a7b 100644 --- a/app/src/main/java/ch/nuth/zhaw/exbox/SortServer.java +++ b/app/src/main/java/ch/nuth/zhaw/exbox/SortServer.java @@ -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) {