Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Quick sort problem Attached is my code but it doesn't pass the test cas es . Please modify my code to make it pass all
Quick sort problem
Attached is my code but it doesn't pass the test cas
es Please modify my code to make it pass all test cases. In C please.
#include
using namespace std;
int swaps ;
int ReadNumsint& size
cin size;
int numbers new intsize;
for int i ; i size; i
cin numbersi;
return numbers;
void PrintNumsint numbers, int left, int right
for int i left; i right; i
cout numbersi;
if i right
cout ;
cout endl;
int Partitionint numbers, int left, int right
int pivot numbersright;
int i left ;
for int j left; j right; j
if numbersj pivot
i;
swapnumbersi numbersj;
swaps;
swapnumbersi numbersright;
swaps;
return i ;
void QuickSortint numbers, int left, int right
if left right
int pivotIndex Partitionnumbers left, right;
cout "Pivot: numberspivotIndex endl;
cout "Pivoted Array: ;
PrintNumsnumbers left, right;
QuickSortnumbers left, pivotIndex ;
QuickSortnumbers pivotIndex right;
else
cout "Left Side: ;
PrintNumsnumbers left, right;
cout "Right Side: endl;
int main
int size ;
int numbers ReadNumssize;
cout "Unsorted:" endl;
PrintNumsnumbers size ;
QuickSortnumbers size ;
cout "Sorted:" endl;
PrintNumsnumbers size ;
cout "Swaps: swaps endl;
delete numbers;
return ;
For input :
indicates how many numbers are needed to sortedin number needed to sorted
the output will be:
Unsorted:
Pivot:
Pivot:
Pivot:
Left Side:
Pivot:
Left Side:
Right Side:
Right Side:
Left Side:
Right Side:
Left Side:
Right Side:
Sorted:
Swaps:
other input will be
output for other input
Unsorted:
Pivot:
Left Side:
Pivot:
Pivot:
Left side:
Pivot:
Pivot:
Left side:
Pivot:
Expected output
Pivot:
Left Side:
Right side:
Left Side:
Right side:
Right Side:
Left Side:
Right side:
Right side:
Left Side:
Right side:
Right side:
Sorted:
Swaps: Unsorted:
Pivot:
Left side:
Pivot:
Left side:
Pivot:
Left side:
Pivot:
Left Side:
Pivot:
Expected output Left Side:
Pivot:
Left Side:
Pivot:
Left Side:
Right side:
Right Side:
Right Side:
Right Side:
Right side:
Right side:
Right Side:
Sorted:
Swaps:
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