R2D2 Sortieralgorithmus angepasst
parent
dabe1dda0f
commit
42d4f44e02
|
@ -57,16 +57,16 @@ public class R2D2 implements Robot {
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public int[] think(int[] zahlen) throws RobotException {
|
public int[] think(int[] zahlen) throws RobotException {
|
||||||
int n = zahlen.length;
|
for (int i = 0; i < zahlen.length - 1; i++) {
|
||||||
for (int i = 1; i < n; ++i) {
|
for (int j = i + 1; j < zahlen.length; j++) {
|
||||||
int key = zahlen[i];
|
if (zahlen[i] > zahlen[j]) {
|
||||||
int j = i - 1;
|
int temp = zahlen[i];
|
||||||
while (j >= 0 && zahlen[j] > key) {
|
zahlen[i] = zahlen[j];
|
||||||
zahlen[j + 1] = zahlen[j];
|
zahlen[j] = temp;
|
||||||
j = j - 1;
|
}
|
||||||
}
|
}
|
||||||
zahlen[j + 1] = key;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return zahlen;
|
return zahlen;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue