Question: Please modify my C++ Quicksort Algorithm: #include using namespace std; void quickSort(int list[], int low, int high); /eed to pass the itneger array into QuickSort

Please modify my C++ Quicksort Algorithm: #include using namespace std; void quickSort(intPlease modify my C++ Quicksort Algorithm:

#include using namespace std;

void quickSort(int list[], int low, int high); /eed to pass the itneger array into QuickSort int partition(int list[], int low, int high); //returns pivot index void swap(int &a, int &b); //can change the lows and highs in the list

int main() { return 0; }

void quickSort(int list[], int low, int high) { if (low and you have 1 number { int pivotIndex = partition(list, low, high); quickSort(list, low, pivotIndex - 1); quickSort(list, pivotIndex + 1, high);

} }

int partition(int list[], int low, int high) //want to return Pivot Index (where pivot is) { int pivot = list[low]; /eed to recursive call, so dont hardcode zero int pivotIndex = low;

for (int i = low + 1; i

//put pivot to the correct position

swap(list[low], list[pivotIndex]);

return pivotIndex; }

void swap(int &a, int &b) //pass by reference to change the lows and highs { int temp = a; a = b; b = temp; }

2. Modified Quicksort II Choosing a pivot value can influence the efficiency of quicksort a lot. Ideally, the pivot should be the median value of the array, which results in equally sized left subarray and right subarray. However, finding median itself is non-trivial. We can approximate the median by the median of three elements in the array: the first, the last, and the center. This is fast and it has a good chance of giving us something close to the real median Left Center Right 86 29 Median is 44 For both problems, rewrite the partition function and demonstrate the modified quicksort algorithms

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!