Fixed order of merges of the remaining stack

This commit is contained in:
finnm 2024-12-10 17:11:58 +01:00
parent 1aaac3729e
commit db340a89a3

View File

@ -33,7 +33,7 @@ public class FinnSort {
i = j;
}
while (runs.size() >= 2) {
basicMerge(a, runs.removeFirst(), runs.removeFirst());
basicMerge(a, runs.removeLast(), runs.removeLast());
}
}
@ -70,10 +70,11 @@ public class FinnSort {
}
int n_1 = run1.end - run1.start;
int n_2 = run2.end - run2.start;
double a = ((double) run1.start + 0.5 * n_1 - 1) / n;
double b = ((double) run2.start + 0.5 * n_2 - 1) / n;
double a = ((double) run1.start + 0.5d * n_1 - 1d) / n;
double b = ((double) run2.start + 0.5d * n_2 - 1d) / n;
int l = 0;
while ((int) (a * pow(2, l)) == (int) (b * pow(2 ,l))) {
l++;
}
return l;