fertig
parent
fe10a94d3b
commit
eaa8aa4a5f
|
|
@ -2,8 +2,8 @@
|
|||
public class SortAlgo {
|
||||
|
||||
public static void main (String[] args) {
|
||||
int[] bubble = {6,3,1,5,2,4};
|
||||
int[] select = {3,6,1,5,2,4};
|
||||
int[] bubble = {6,5,4,3,2,1};
|
||||
int[] select = {6,5,4,3,2,1};
|
||||
int[] insert = {3,6,1,5,2,4};
|
||||
|
||||
int[] erg1 = bubblesort(bubble);
|
||||
|
|
@ -18,9 +18,9 @@ public class SortAlgo {
|
|||
|
||||
System.out.println();
|
||||
|
||||
//int[] erg3 = insertionsort(insert);
|
||||
//for (int i = 0; i < erg3.length;i++)
|
||||
//System.out.print(erg3[i] + " ");
|
||||
int[] erg3 = insertionsort(insert);
|
||||
for (int i = 0; i < erg3.length;i++)
|
||||
System.out.print(erg3[i] + " ");
|
||||
}
|
||||
|
||||
public static int[] bubblesort (int[] arr) {
|
||||
|
|
@ -54,6 +54,17 @@ public class SortAlgo {
|
|||
}
|
||||
|
||||
public static int[] insertionsort (int[] arr) {
|
||||
for (int i = 0; i < arr.length - 1 ;i++) {
|
||||
if (arr[i+1] < arr[i]) {
|
||||
int m = arr[i+1];
|
||||
int j = i;
|
||||
while (j >= 0 && arr[j] > m) {
|
||||
arr[j+1] = arr[j];
|
||||
j--;
|
||||
}
|
||||
arr[j+1] = m;
|
||||
}
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue