2022-12-08 14:58:44 +01:00
|
|
|
package domain;
|
|
|
|
|
2022-12-14 09:48:20 +01:00
|
|
|
import robot.interfaces.Sorting;
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
2022-12-09 00:30:35 +01:00
|
|
|
public class R2D2 extends RobotBasics {
|
2022-12-08 23:34:47 +01:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
* @param id> int
|
|
|
|
* @param name> String
|
|
|
|
*/
|
2022-12-08 23:13:22 +01:00
|
|
|
public R2D2(int id, String name){
|
2022-12-09 01:38:11 +01:00
|
|
|
super(id, name);
|
2022-12-14 09:48:20 +01:00
|
|
|
}
|
2022-12-09 01:38:11 +01:00
|
|
|
|
2022-12-14 09:48:20 +01:00
|
|
|
public String sorting(int[] arr) {
|
|
|
|
//Selectionsort
|
|
|
|
int small;
|
|
|
|
for (int i = 0; i <arr.length - 1; i++) {
|
|
|
|
small = i;
|
|
|
|
for (int j = i + 1; j < arr.length; j++) {
|
|
|
|
//if there is a smaller number on this position
|
|
|
|
if (arr[j] < arr[small]) {
|
|
|
|
small = j;
|
|
|
|
//swap values
|
|
|
|
int temp = arr[i];
|
|
|
|
arr[i] = arr[small];
|
|
|
|
arr[small] = temp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//Writing all values of the array into a String
|
|
|
|
String result = "";
|
|
|
|
if(arr.length != 0) {
|
|
|
|
result = "" + arr[0];
|
|
|
|
if (arr.length > 1) {
|
|
|
|
for (int i = 1; i < arr.length; i++) {
|
|
|
|
result += "," + arr[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
2022-12-08 23:13:22 +01:00
|
|
|
}
|
2022-12-08 23:34:47 +01:00
|
|
|
|
2022-12-08 14:58:44 +01:00
|
|
|
}
|