mirror of
https://gitlab.uni-marburg.de/langbeid/powersort.git
synced 2025-01-21 19:50:35 +01:00
Fixed FinnSort: Cleared runs for every method call
This commit is contained in:
parent
fa70412791
commit
e182ecc756
@ -5,10 +5,12 @@ import static java.lang.Math.*;
|
||||
|
||||
public class FinnSort {
|
||||
|
||||
private static final ArrayList<Run> runs = new ArrayList<>();
|
||||
private static ArrayList<Run> runs;
|
||||
|
||||
public static <T> void sort(T[] a, Comparator<? super T> c) {
|
||||
|
||||
runs = new ArrayList<>();
|
||||
|
||||
int n = a.length;
|
||||
int i = 0;
|
||||
int j = extendRunRight(a, i, c);
|
||||
@ -42,14 +44,22 @@ public class FinnSort {
|
||||
ArrayList<T> run2 = new ArrayList<>(Arrays.asList(a).subList(r2.start, r2.end));
|
||||
ArrayList<T> merge = new ArrayList<>();
|
||||
|
||||
while (!run1.isEmpty() || !run2.isEmpty()) {
|
||||
if (run2.isEmpty() || !run1.isEmpty() && c.compare(run1.getFirst(), run2.getFirst()) < 0) {
|
||||
while (!run1.isEmpty() && !run2.isEmpty()) {
|
||||
if (c.compare(run1.getFirst(), run2.getFirst()) < 0) {
|
||||
merge.add(run1.removeFirst());
|
||||
} else {
|
||||
merge.add(run2.removeFirst());
|
||||
}
|
||||
}
|
||||
|
||||
while (!run1.isEmpty()) {
|
||||
merge.add(run1.removeFirst());
|
||||
}
|
||||
|
||||
while (!run2.isEmpty()) {
|
||||
merge.add(run2.removeFirst());
|
||||
}
|
||||
|
||||
System.arraycopy(merge.toArray(), 0, a, min(r1.start, r2.start), merge.size());
|
||||
Run r = new Run(min(r1.start, r2.start), max(r1.end, r2.end), min(r1.power, r2.power));
|
||||
runs.add(r);
|
||||
|
Loading…
x
Reference in New Issue
Block a user