parent
5f6388a787
commit
9ea52002a7
|
|
@ -16,41 +16,28 @@ public class Main {
|
||||||
|
|
||||||
public static int[] sortiereArray(int[] array) {
|
public static int[] sortiereArray(int[] array) {
|
||||||
|
|
||||||
boolean fertig = false;
|
int temp;
|
||||||
int temp = 0;
|
|
||||||
int zaehlerPruefungen = 0;
|
int zaehlerPruefungen = 0;
|
||||||
int zaehlerTauschvorgaenge = 0;
|
int zaehlerTauschvorgaenge = 0;
|
||||||
|
|
||||||
while (!fertig) {
|
for (int i = 0; i < array.length - 1; i++) {
|
||||||
|
zaehlerPruefungen++;
|
||||||
|
if (array[i] > array[i + 1]) {
|
||||||
|
temp = array[i];
|
||||||
|
array[i] = array[i + 1];
|
||||||
|
array[i + 1] = temp;
|
||||||
|
zaehlerTauschvorgaenge++;
|
||||||
|
|
||||||
for (int i = 0; i < array.length - 1; i++) {
|
for (int j = i; j > 0; j--) {
|
||||||
|
|
||||||
zaehlerPruefungen++;
|
|
||||||
fertig = true;
|
|
||||||
|
|
||||||
if (array[i] > array[i + 1]) {
|
|
||||||
fertig = false;
|
|
||||||
temp = array[i];
|
|
||||||
array[i] = array[i + 1];
|
|
||||||
array[i + 1] = temp;
|
|
||||||
zaehlerTauschvorgaenge++;
|
|
||||||
zaehlerPruefungen++;
|
zaehlerPruefungen++;
|
||||||
|
if (array[j] < array[j - 1]) {
|
||||||
for (int j = i; j > 0; j--) {
|
temp = array[j];
|
||||||
if (array[j] < array[j - 1]) {
|
array[j] = array[j - 1];
|
||||||
temp = array[j];
|
array[j - 1] = temp;
|
||||||
array[j] = array[j - 1];
|
zaehlerTauschvorgaenge++;
|
||||||
array[j - 1] = temp;
|
} else {
|
||||||
zaehlerTauschvorgaenge++;
|
break;
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i == array.length - 1) {
|
|
||||||
fertig = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue