InsertionSort nochmals geübt
parent
44d1dd85c2
commit
10438f9e7a
|
|
@ -1,36 +1,12 @@
|
|||
|
||||
public class InsertionSort {
|
||||
public static void main(String[] args) {}
|
||||
|
||||
|
||||
public static int[] insertionSort(int[] sortieren) {
|
||||
int temp = 0;
|
||||
|
||||
for(int i = 1; i < sortieren.length; i++) {
|
||||
if(sortieren[i-1] > sortieren[i]) {
|
||||
temp=sortieren[i];
|
||||
sortieren[i]=sortieren[i-1];
|
||||
sortieren[i-1]=temp;
|
||||
|
||||
int j = i;
|
||||
while(j>0) {
|
||||
if(sortieren[j-1]>sortieren[j]) {
|
||||
temp=sortieren[j];
|
||||
sortieren[j]=sortieren[j-1];
|
||||
sortieren[j-1]=temp;
|
||||
}
|
||||
j--;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hier ist Insertionsort");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return sortieren;
|
||||
}
|
||||
|
||||
public static int[] insertionSortLSG(int[] sortieren) {
|
||||
int temp;
|
||||
for (int i = 1; i < sortieren.length; i++) {
|
||||
|
|
@ -38,10 +14,29 @@ public class InsertionSort {
|
|||
int j = i;
|
||||
while (j > 0 && sortieren[j - 1] > temp) {
|
||||
sortieren[j] = sortieren[j - 1];
|
||||
j--;
|
||||
}
|
||||
j--; }
|
||||
sortieren[j] = temp;
|
||||
}
|
||||
return sortieren;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void insertionsorttest(int[] arr){
|
||||
int tmp;
|
||||
for(int i =1; i <arr.length; i++){
|
||||
tmp = arr[i];
|
||||
int j = i;
|
||||
|
||||
while(j > 0 && arr[j-1]>tmp){
|
||||
arr[j] = arr[j-1];
|
||||
}
|
||||
arr[j]=tmp;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void main() {
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue