Insertionsort
Public static void insertionSort(int[]a){
for (int i = 1; i < a.length; i++){
int x = a[i];
int j = i;
while (j > 0; && a[j-1] > x){
a[j] = a[j-1];
a[j-1] = x;
j--;
}
Selectionsort
public static void selectionSort(int[] a){
for (int i = 0; i < a.length -1; i++){
int least = i;
for ( int j = i + 1; j < a.length; j++){
if (a[j] < a[least])
least = j;
if (least != i){
int swap = a[i];
a[i] = a[least];
a[least] = swap;
Bubblesort
public static void bubbleSort(int [] a){
boolean swapped;
do {
swapped = false;
for (int i=1; i<a.length; i++)
if( a[i - 1] > a[i];
a[i] = a[i-1];
a[i-1] = swap;
swapped = true;
while (swapped);
Zuletzt geändertvor 2 Jahren