Question: quickselect.cpp * Author : * Pledge : * Date : * Description : Implements the quickselect algorithm. * * * * * * * *
quickselect.cpp
Author :
Pledge :
Date :
Description : Implements the quickselect algorithm.
#include
#include
#include
#include
using namespace std;
sizet lomutopartitionint array sizet left, sizet right
TODO
DO NOT change the function header in any way, otherwise you will lose
points.
return ;
int quickselectint array sizet left, sizet right, sizet k
TODO
DO NOT change the function header in any way, otherwise you will lose
points.
return ;
int quickselectint array const sizet length, sizet k
return quickselectarray length k;
int mainint argc, char argv
if argc
cerr "Usage: argv endl;
return ;
int k;
istringstream iss;
iss.strargv;
if iss k k
cerr "Error: Invalid value argv for k endl;
return ;
cout "Enter sequence of integers, each followed by a space: flush;
int value, index ;
vector values;
string str;
strreserve;
char c;
iss.clear;
while true
c getchar;
const bool eoln c r c
;
if isspacec eoln
if strlength
iss.strstr;
if iss value
values.pushbackvalue;
else
cerr "Error: Noninteger value str
received at index index endl;
return ;
iss.clear;
index;
if eoln
break;
strclear;
else
str c;
int numvalues values.size;
if numvalues
cerr "Error: Sequence of integers not received." endl;
return ;
TODO error checking k against the size of the input
TODO call the quickselect function and display the result
return ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
