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