ich hab zu Übungszwecken für meine Klausur mal ein kleines Programm in Java zum Algorithmus SelectionSort geschrieben. Falls ihr eine bessere Idee habt nur her damit
- Code: Alles auswählen
import java.lang.*;
public class SelectionSort2 {
public static void main(String[] args) {
sortieren(new int[] {12, 4, 66, 34, 62, 2, 3, 7, 1, 678});
}
public static void sortieren(int[] a) {
System.out.println("SelectionSort");
//SelectionSort-Algorithmus
for(int i = 0; i < a.length; i++) {
for(int j = i; j < a.length; j++) {
if(a[j] < a[i]) {
int temp = a[j];
a[j] = a[i];
a[i] = temp;
}
}
}
//das hier ist nur die Ausgabe des SelectionSort-Algorithmus
for(int i = 0; i < a.length; i++) {
System.out.println(a[i]);
}
}
}
Natürlich kann man das auch ein wenig abändern, doch ich hab das jetzt mal so geschrieben ...
