From c696e79cbf31d02c331ed0caff32165d76348c36 Mon Sep 17 00:00:00 2001 From: nikow Date: Tue, 3 Jan 2023 17:50:14 +0100 Subject: [PATCH] R2D2 Selection Sort implementiert. --- Roboterfabrik/src/Domäne/R2D2.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Roboterfabrik/src/Domäne/R2D2.java b/Roboterfabrik/src/Domäne/R2D2.java index f366261..25d73e5 100644 --- a/Roboterfabrik/src/Domäne/R2D2.java +++ b/Roboterfabrik/src/Domäne/R2D2.java @@ -21,8 +21,21 @@ public class R2D2 extends Roboter { @Override public int[] think(int[] zahlen) throws RobotException { + int remember; - return null; + for (int i = 0; i < zahlen.length - 1; i++) { + int smallest = i; + + for (int k = i+1; k < zahlen.length; k++) { + if (zahlen[i] < zahlen[smallest]) { + smallest = k; + } + } + remember = zahlen[i]; + zahlen[i] = zahlen[smallest]; + zahlen[smallest] = remember; + } + return zahlen; } @Override