rendered paste bodypublic class SelectionSort implements Sorter {
private Comparable unsortiert[];
private boolean ende = false;
private int kleinstesE = -1;
private int zaehler = 0;
private int next = 0;
private Object sortiert[];
public void sort(Comparable[] data) {
this.unsortiert = new Comparable[data.length];
this.sortiert = new Object[data.length];
if (data.length == 0) {
System.out.println("Leere Menge");
return;
} else {
for (int next = 0; next < data.length; next++) {
this.unsortiert[next] = data[next];
}
}
do {
findMinimum(unsortiert, next);
this.next++;
System.out.println(next);
} while (ende == false);
return;
}
private void findMinimum(Comparable[] data, int next) {
if (kleinstesE == -1) {
this.kleinstesE = next;
} else if (0 > data[next].compareTo(data[kleinstesE])) {
this.kleinstesE = next;
}
if (next == (data.length - 1) - zaehler) {
swap(data, kleinstesE);
}
}
private void swap(Comparable[] data, int kleinstesE) {
this.sortiert[zaehler] = data[kleinstesE];
this.unsortiert[kleinstesE] = unsortiert[(unsortiert.length - 1)
- zaehler];
this.unsortiert[(unsortiert.length - 1) - zaehler] = null;
this.kleinstesE = 0;
this.zaehler++;
this.next = 0;
if (kleinstesE == 1 & unsortiert[2] == null) {
this.sortiert[sortiert.length - 1] = unsortiert[0];
this.unsortiert = null;
this.ende = true;
return;
}
}
public Object [] getSorted() {
for (int i = 0; i < sortiert.length;i++)
return sortiert[i];
}
}