From 42d4f44e02882c21bf921e457bd26d90f63fc28e Mon Sep 17 00:00:00 2001 From: azadehobenland Date: Thu, 5 Jan 2023 18:16:25 +0100 Subject: [PATCH] R2D2 Sortieralgorithmus angepasst --- src/R2D2.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/R2D2.java b/src/R2D2.java index 502f6fa..4deef9a 100644 --- a/src/R2D2.java +++ b/src/R2D2.java @@ -57,16 +57,16 @@ public class R2D2 implements Robot { } @Override public int[] think(int[] zahlen) throws RobotException { - int n = zahlen.length; - for (int i = 1; i < n; ++i) { - int key = zahlen[i]; - int j = i - 1; - while (j >= 0 && zahlen[j] > key) { - zahlen[j + 1] = zahlen[j]; - j = j - 1; + for (int i = 0; i < zahlen.length - 1; i++) { + for (int j = i + 1; j < zahlen.length; j++) { + if (zahlen[i] > zahlen[j]) { + int temp = zahlen[i]; + zahlen[i] = zahlen[j]; + zahlen[j] = temp; + } } - zahlen[j + 1] = key; } + return zahlen; } }