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