Arbeit #4

Merged
3024753 merged 2 commits from Arbeit into main 2026-03-31 18:30:10 +02:00
2 changed files with 51 additions and 29 deletions

View File

@ -0,0 +1,51 @@
public class QuickSort {
public static void quickSort(int[] arr, int low, int high) {
if (low < high) {
// Pivot-Index bestimmen
int pivotIndex = partition(arr, low, high);
// Linke Seite sortieren
quickSort(arr, low, pivotIndex - 1);
// Rechte Seite sortieren
quickSort(arr, pivotIndex + 1, high);
}
}
private static int partition(int[] arr, int low, int high) {
int pivot = arr[high]; // letztes Element als Pivot
int i = low - 1;
for (int j = low; j < high; j++) {
if (arr[j] <= pivot) {
i++;
// Tauschen
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
// Pivot an richtige Position setzen
int temp = arr[i + 1];
arr[i + 1] = arr[high];
arr[high] = temp;
return i + 1;
}
// Test
public static void main(String[] args) {
int[] arr = {8, 3, 1, 7, 0, 10, 2};
quickSort(arr, 0, arr.length - 1);
for (int num : arr) {
System.out.print(num + " ");
}
}
//End of Class
}

View File

@ -93,33 +93,4 @@ public class SelectionSort {
}
}