Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

I have the following code for a C++ QuickSort algorithm: #include using namespace std; void quickSort(int list[], int low, int high); /eed to pass the

I have the following code for a 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; }

I need to modify it to do the following:

Please utilize my code and show commented code! (Rewrite the partition function and demonstrate the modified quicksort algorithm.)

image text in transcribed

1. Modified Quicksort I Reduce the number of swaps using the following approach: * K Keep a leftlndex starting at the beginning of the array and a rightlndex starting from the end of the array. These track the current elements being examined that should be stored on the left of the pivot and on the right of the pivot. The two variables move in alternating steps efilndex increments and rightlndex decrements The left scan stops if it sees a larger element than the pivot; the right scan stops if it sees ne left scan stops if t sees a larger element than the pivot; the a smaller element than the pivot; then swap the two. . This continues until left crosses right

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Access Patterns Database Interactions In Object Oriented Applications

Authors: Clifton Nock

1st Edition

0321555627, 978-0321555625

Students explore these related Databases questions

Question

Explain the Pascals Law ?

Answered: 3 weeks ago