This commit is contained in:
2020-06-08 12:35:06 -05:00
parent cb3dca5d62
commit 8ddce68e4d

View File

@@ -4,21 +4,23 @@ package Sorting;
* an implementation of quick sort with three-way partitioning
*/
public class QuickSorterThreeWay extends QuickSorter{
public class QuickSorterThreeWay extends Sorter{
public QuickSorterThreeWay(String filename){
super("3-way partitioned quick", filename);
super("quick sort (3-way partition)", filename);
}
void sort(){
quickSort(0,numbers.length-1);
}
//edit this to use three-way partition
@Override
void quickSort(int lowIndex, int highIndex){
if(compare(lowIndex,highIndex)<0){
int pivot=numbers[highIndex];
int lessThan = lowIndex;
int greaterThan = highIndex;
int i = greaterThan-1;
while(i>lessThan){
while(i>=lessThan){
int comp = compare(numbers[i], pivot);
if(comp>0){
swap(i, greaterThan);