mirror of
https://gitlab.uni-marburg.de/langbeid/powersort.git
synced 2025-01-21 19:50:35 +01:00
Handling of descending runs
This commit is contained in:
parent
8c75ff36cd
commit
a2dd6ac325
@ -15,7 +15,7 @@ public class FinnSort {
|
||||
int i = 0;
|
||||
int j = extendRunRight(a, i, c);
|
||||
|
||||
// printList(a, c);
|
||||
//printList(a, c);
|
||||
|
||||
runs.add(new Run(i, j, 0));
|
||||
|
||||
@ -63,17 +63,40 @@ public class FinnSort {
|
||||
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);
|
||||
// printList(a, c);
|
||||
//printList(a, c);
|
||||
}
|
||||
|
||||
private static <T> int extendRunRight(T[] a, int i, Comparator<? super T> c) {
|
||||
if (i >= a.length - 1)
|
||||
return i + 1;
|
||||
|
||||
|
||||
int j = i + 1;
|
||||
while (j < a.length && c.compare(a[j-1], a[j]) <= 0) {
|
||||
j++;
|
||||
if (c.compare(a[i], a[j]) < 0) { //
|
||||
while (j < a.length && c.compare(a[j - 1], a[j]) <= 0) {
|
||||
j++;
|
||||
}
|
||||
} else {
|
||||
while (j < a.length && c.compare(a[j - 1], a[j]) >= 0) {
|
||||
j++;
|
||||
}
|
||||
makeAscending(a, i, j);
|
||||
}
|
||||
return j;
|
||||
}
|
||||
|
||||
private static <T> void makeAscending(T[] a, int i, int j) {
|
||||
for (int p = 0; p < (j - i) / 2; p++) {
|
||||
swap(a, i + p ,j - p - 1);
|
||||
}
|
||||
}
|
||||
|
||||
private static <T> void swap(T[] a, int i, int j) {
|
||||
T temp = a[i];
|
||||
a[i] = a[j];
|
||||
a[j] = temp;
|
||||
}
|
||||
|
||||
private static int power(Run run1, Run run2, int n) {
|
||||
if (run1.start == 0) {
|
||||
return 0;
|
||||
@ -89,7 +112,7 @@ public class FinnSort {
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
/*
|
||||
public static void printRuns() {
|
||||
String s = "";
|
||||
for (Run run : runs) {
|
||||
@ -111,4 +134,6 @@ public class FinnSort {
|
||||
}
|
||||
System.out.println(s);
|
||||
}
|
||||
|
||||
*/
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user