InsertionSort in C3PO implementiert

master
nikow 2023-01-03 17:25:38 +01:00
parent e90209a20d
commit 8396f15947
1 changed files with 13 additions and 2 deletions

View File

@ -22,8 +22,19 @@ public class C3PO extends Roboter{
@Override
public int[] think(int[] zahlen) throws RobotException {
// TODO Auto-generated method stub
return null;
int remember;
for (int i = 1; i < zahlen.length; i++) {
remember = zahlen[i];
int k = i;
while (k > 0 && zahlen[k - 1] < remember) {
zahlen[k] = zahlen[k - 1];
k--;
}
zahlen[k] = remember;
}
return zahlen;
}
}