bug fix
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user