From 45b8f7b164deea2914ad81084c4fc7f58d714308 Mon Sep 17 00:00:00 2001 From: cedri Date: Sat, 7 Jan 2023 20:19:41 +0100 Subject: [PATCH] Aufsteigende Sortierung der Zahlen in R2D2 geschrieben --- Robbie-Management-System/src/domain/R2D2.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Robbie-Management-System/src/domain/R2D2.java b/Robbie-Management-System/src/domain/R2D2.java index 2d6c7a5..b869779 100644 --- a/Robbie-Management-System/src/domain/R2D2.java +++ b/Robbie-Management-System/src/domain/R2D2.java @@ -15,8 +15,22 @@ public class R2D2 extends Robotermodell implements Robot { @Override public int[] think(int[] zahlen) throws RobotException { - // TODO Auto-generated method stub - return null; + for (int i = 0; i < zahlen.length; i++) { + int kMin = i; + for (int k = i + 1; k < zahlen.length; k++) { + if (zahlen[k] < zahlen[kMin]) { + kMin = k; + } + } + + if(kMin != i) { + int zwischenspeicher = zahlen[i]; + zahlen[i] = zahlen[kMin]; + zahlen[kMin] = zwischenspeicher; + } + } + + return zahlen; } }