Question
Can anyone please fix this program? #include using namespace std; const int SIZE = 5; int kSmall(int k, const int anArray[], int first, int last);
Can anyone please fix this program?
#include
using namespace std;
const int SIZE = 5;
int kSmall(int k, const int anArray[], int first, int last);
void partition(int anArray[], int size, int pivotValue, int& pivotIndex);
int main()
{
return 0;
}
int kSmall(int k, int anArray[], int first, int last)
{
int pivotIndex = first;
int p = anArray[first];
partition(anArray, SIZE, int pivotValue, pivotIndex);
if(k
{
return kSmall(k, anArray, first, pivotIndex - 1)
}
else if(k == pivotIndex - first + 1)
{
return p;
}
else
{
return kSmall(k - (pivotIndex - first + 1), anArray, pivotIndex + 1, last);
}
}
void partition(int anArray[], int first, int last, int& pivotIndex)
{
int pivot = anArray[first];
int lastS1 = first;
int firstUnknown = first + 1;
for( firstUnknown
{
if(anArray[firstUnknown]
{
++lastS1;
swap(anArray[firstUnknown], anArray[lastS1]);
}
}
swap(anArray[first], anArray[lastS1]);
pivotIndex = lastS1;
}
/Returns the kth smallest value in anArray[first..last] kSmall(k: integer, anArray: ArrayType, irst: integer, last: integer): ValueType Choose a pivot value p from anArray[first..last] Partition the values of anArray[firstlast] about p if (kStep 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