Unify insertionSort methods

This commit is contained in:
Manuel Thalmann 2022-12-13 00:19:29 +01:00
parent 27d815812e
commit 88ca5cf6a0

View file

@ -34,7 +34,11 @@ public class SortServer implements CommandExecutor {
}
private void insertionSort(int[] a) {
for (int k = 0; k < a.length; k++) {
insertionSort(a, 0, a.length - 1);
}
private void insertionSort(int[] a, int min, int max) {
for (int k = min; k < max + 1; k++) {
int item = a[k];
int newIndex;
@ -46,19 +50,6 @@ public class SortServer implements CommandExecutor {
}
}
private void insertionSort(int[] a, int l, int r) {
for (int k = l + 1; k < r + 1; k++) {
if (a[k] < a[k - 1]) {
int x = a[k];
int i;
for (i = k; ((i > 0) && (a[i - 1] > x)); i--) {
a[i] = a[i - 1];
}
a[i] = x;
}
}
}
private void selectionSort(int[] a) {
// TODO Implement Aufgabe 3
for (int i = 0; i < a.length; i++) {