Logarithmus verbessert

This commit is contained in:
Marc Koch 2020-05-08 10:10:06 +02:00
parent cf2729c045
commit e29bb7323f
Signed by: marc
GPG Key ID: AC2D4E00990A6767
1 changed files with 21 additions and 3 deletions

View File

@ -9,8 +9,8 @@ public class Main {
static int[] array3 = {7, 14, 21, 28, 35, 42};
public static void main(String[] args) {
System.out.println(Arrays.toString(array3));
System.out.println(Arrays.toString(sortiereArray(array3)));
System.out.println(Arrays.toString(array1));
System.out.println(Arrays.toString(sortiereArray(array1)));
}
@ -18,18 +18,34 @@ public class Main {
boolean fertig = false;
int temp = 0;
int zaehlerDurchlaeufe = 0;
int zaehlerTauschvorgaenge = 0;
while (!fertig) {
for (int i = 0; i < array.length - 1; i++) {
fertig = true; // VERBESSERUNG
zaehlerDurchlaeufe++;
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--) {
if (array[j] < array[j - 1]) {
temp = array[j];
array[j] = array[j - 1];
array[j - 1] = temp;
zaehlerTauschvorgaenge++;
} else {
break;
}
}
break;
}
@ -39,6 +55,8 @@ public class Main {
}
}
System.out.println("\nTauschvorgänge: " + zaehlerTauschvorgaenge);
System.out.println("Durchläufe: " + zaehlerDurchlaeufe);
return array;
}