From 88ca5cf6a064f1f5912f7965589b87d588de123b Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Tue, 13 Dec 2022 00:19:29 +0100 Subject: [PATCH] Unify `insertionSort` methods --- .../java/ch/nuth/zhaw/exbox/SortServer.java | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) 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 bbaede8..0a825fd 100644 --- a/app/src/main/java/ch/nuth/zhaw/exbox/SortServer.java +++ b/app/src/main/java/ch/nuth/zhaw/exbox/SortServer.java @@ -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++) {