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
@ -67,13 +67,36 @@ public class FinnSort {
|
||||
}
|
||||
|
||||
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;
|
||||
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