Compare commits

..

No commits in common. "0d33b585c40acf206c0e9d59ed2cc10b52002d7e" and "0c179912de4b9216a9b4e3c9174566563320cbbf" have entirely different histories.

2 changed files with 29 additions and 51 deletions

View File

@ -1,51 +0,0 @@
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,4 +93,33 @@ public class SelectionSort {
}
}