Implement the ParallelQuickerSortServer

This commit is contained in:
Manuel Thalmann 2022-12-13 01:48:38 +01:00
parent 0ad3397ad0
commit a410e816f4

View file

@ -26,16 +26,68 @@ public class ParallelQuickerSortServer extends Thread implements CommandExecutor
if (left < right) {
// TODO Aufgabe 12.3
mid = partition(arr, left, right);
if (mid - left > SPLIT_THRESHOLD) {
t1 = new ParallelQuickerSortServer(arr, left, mid - 1);
t1.start();
} else {
quickerSort(arr, left, mid - 1);
}
if (right - mid > SPLIT_THRESHOLD) {
t2 = new ParallelQuickerSortServer(arr, mid, right);
t2.start();
} else {
quickerSort(arr, mid, right);
}
}
if (t1 != null) {
try {
t1.join();
} catch (InterruptedException e) {}
}
if (t2 != null) {
try {
t2.join();
} catch (InterruptedException e) {}
}
}
private void quickerSort(int[] arr, int left, int right) {
// TODO Aus Aufgabe 12.1 übernehmen
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) {
// TODO Aus Aufgabe 12.1 übernehmen
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 void insertionSort(int[] a, int l, int r) {