Algorithmus optimiert

while-Schleife entfernt
This commit is contained in:
Marc Koch 2020-05-08 10:21:41 +02:00
parent 5f6388a787
commit 9ea52002a7
Signed by: marc
GPG Key ID: AC2D4E00990A6767
1 changed files with 16 additions and 29 deletions

View File

@ -16,27 +16,20 @@ 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++;
fertig = true;
if (array[i] > array[i + 1]) {
fertig = false;
temp = array[i];
array[i] = array[i + 1];
array[i + 1] = temp;
zaehlerTauschvorgaenge++;
zaehlerPruefungen++;
for (int j = i; j > 0; j--) {
zaehlerPruefungen++;
if (array[j] < array[j - 1]) {
temp = array[j];
array[j] = array[j - 1];
@ -46,12 +39,6 @@ public class Main {
break;
}
}
}
if (i == array.length - 1) {
fertig = true;
}
}
}