fix: QuickSort

This commit is contained in:
Daniel Langbein 2024-12-30 16:10:37 +00:00
parent d06cb9eebd
commit 4528a544b7
Signed by: langfingaz
GPG Key ID: 6C47C753F0823002
4 changed files with 13 additions and 12 deletions

View File

@ -127,8 +127,8 @@ public final class DualPivotQuicksort {
* @param pivotIndex2 the index of pivot2, the second pivot
* @param po the method reference for the fallback implementation
*/
private static <A> int[] partition(A array, int high, int pivotIndex1, int pivotIndex2, PartitionOperation<A> po) {
return po.partition(array, 0, high, pivotIndex1, pivotIndex2);
private static <A> int[] partition(A array, int low, int high, int pivotIndex1, int pivotIndex2, PartitionOperation<A> po) {
return po.partition(array, low, high, pivotIndex1, pivotIndex2);
}
/**
@ -279,7 +279,7 @@ public final class DualPivotQuicksort {
* the pivots. These values are inexpensive approximation
* of tertiles. Note, that pivot1 < pivot2.
*/
int[] pivotIndices = partition(a, high, e1, e5, DualPivotQuicksort::partitionDualPivot);
int[] pivotIndices = partition(a, low, high, e1, e5, DualPivotQuicksort::partitionDualPivot);
lower = pivotIndices[0];
upper = pivotIndices[1];
@ -298,7 +298,7 @@ public final class DualPivotQuicksort {
* Use the third of the five sorted elements as the pivot.
* This value is inexpensive approximation of the median.
*/
int[] pivotIndices = partition(a, high, e3, e3, DualPivotQuicksort::partitionSinglePivot);
int[] pivotIndices = partition(a, low, high, e3, e3, DualPivotQuicksort::partitionSinglePivot);
lower = pivotIndices[0];
upper = pivotIndices[1];
/*

View File

@ -37,6 +37,7 @@ public abstract class AbstractSortTest {
Integer[] array = AscendingRuns.newAscendingRuns(numOfRuns, runLength, decreaseBetweenRuns).getCopy();
sortAndCheckResult(array);
}
@ParameterizedTest
@CsvSource({
"2",

View File

@ -1,7 +0,0 @@
package de.uni_marburg.powersort.sort;
public class DualPivotQuicksort extends AbstractSortTest {
DualPivotQuicksort() {
sortAlg = SortEnum.DPQS;
}
}

View File

@ -0,0 +1,7 @@
package de.uni_marburg.powersort.sort;
public class DualPivotQuicksortTest extends AbstractSortTest {
DualPivotQuicksortTest() {
sortAlg = SortEnum.DPQS;
}
}