Question
C++ Recursive *Quick Sort* THIS IS THE THIRD TIME I Post THIS QUESTION. PLEASE READ CAREFULLY. I need FULLY FUNCTIONAL CODE. NOT THEORY based responses.
C++ Recursive *Quick Sort*
THIS IS THE THIRD TIME I Post THIS QUESTION. PLEASE READ CAREFULLY. I need FULLY FUNCTIONAL CODE. NOT THEORY based responses. 1. Please modify the PARTITION function below so that the array gets sorted from least to greatest. 2. pass the quickSort function an array with the following values: 5, 2, 6, 1, 3, 4 ... run the program and show a screenshot showing that it works.
double arr[] = {5, 2, 6, 1, 3, 4};
quickSort(arr, 0, 6);
for (int i = 0; i
Thank YOU!!!
PS: do not change the pivot. Our pivot must be the first element of the array. (what I mean by this is, that there different ways to choose a pivot. You can select a random pivot, make the middle number your pivot, or the last number of the array your pivot... etc... for this assigment, we are required to choose the first number in the array as our pivot)
//--------------------------------
#include
//5, 2, 6, 1, 3, 4 int partition (double * arr, int start, int end) { int pivot = arr[start]; // pivot int i = (start-1); for (int j = end-1; j >= start; --j) { if (pivot >= arr[j]) { i++; swap(arr[i], arr[j]); } } swap(arr[i + 1], arr[end]); return (i + 1); }
void quickSort(double * arr, int start, int end) { if ((end-start)
quickSort(arr, start, pi - 1); quickSort(arr, pi + 1, start); } }
int main() {
double arr[] = {5, 2, 6, 1, 3, 4};
quickSort(arr, 0, 6);
for (int i = 0; i
}
#include
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