Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Modify the QuickSort.java program to count the number of copies and comparisons it makes during a sort and then display the totals. / / /
Modify the QuickSort.java program to count the number of copies and comparisons it makes during a sort and then display the totals.
Modify Code Below To Answer Question
public class QuickSort
static int ab ;
public static void mainString args
printArray;
quickSort ablength;
partitionIt ablength abablength;
printArray;
private static void quickSortint left, int right
base case for recursion
if right left For right value as pivot
if right left For median of three as pviot
manualSortleft left right;
else
int pivotValue abright; For right value as pivot
int pivotValue getMedianOfThreeleft right;
int partitionIndex partitionItleft right, pivotValue;
quickSortleft partitionIndex ;
quickSortpartitionIndex right;
private static int getMedianOfThreeint left, int right
int middle left right;
manualSortleft middle, right;
swapmiddle right;
return abright;
private static void manualSortint left, int middle, int right
if ableft abmiddle
swapleft middle;
if ableft abright
swapleft right;
if abmiddle abright
swapmiddle right;
private static int partitionItint left, int right, int pivotValue
int leftPtr left ;
int rightPtr right;
while true
while ableftPtr pivotValue;
while rightPtr && abrightPtr pivotValue;
if rightPtr leftPtr
swapleftPtr right;
break;
swapleftPtr rightPtr;
return leftPtr;
private static void swapint leftPtr, int rightPtr
int temp ableftPtr;
ableftPtr abrightPtr;
abrightPtr temp;
private static void printArray
for int i ; i ablength; i
System.out.printabi;
System.out.println;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started