Question: This code is supposed to use unseeded rand to generate elements of an array, sort that array in DESCENDING order and have two keys inputted
This code is supposed to use unseeded rand to generate elements of an array, sort that array in DESCENDING order and have two keys inputted one returns "exists" and one returns "does not exist". I do not understand why my code does not sort the array whatsoever and also, apparently I did not assign any values to the array i dont get that Please correct the code and explain what is wrong with it Thank you.
Code :
#include
using namespace std;
bool binarysearchint arrayx int size, int key;
void selectionsortint arrayx int size;
void printarrayint arrayx int size;
int main
int key;
int key;
const int size ;
int arrayxsize;
cout "Enter key endl;
cin key;
printarrayarrayx size;
selectionsort arrayx, size;
binarysearcharrayx size, key;
cout "Enter key endl;
cin key;
binarysearch arrayx, size, key;
printarray arrayx, size;
cout printarray;
selectionsortarrayx size;
cout selectionsort;
void printarrayint arrayx int size
for int i ; i size; i
arrayxi rand;
cout arrayxi;
void selectionsortint arrayx int size
int temp;
for int i ; i size ; i
for int j i; j size; j
if arrayxj arrayxi
temp arrayxi;
arrayxi arrayxj;
arrayxj temp;
bool binarysearchint arrayx int size, int key
bool found false;
int low ;
int high size ;
int middle high low ;
while low high && found false
if arrayxmiddle key
found true;
cout
The key exists.";
else
if arrayxmiddle key
low middle ;
else
high middle ;
middle high low ;
return found;
if found false
cout "The key does not exist ;
else
cout "The key exists";
bool binarysearchint arrayx int size, int key
bool found false;
int low ;
int high size ;
int middle high low ;
while low high && found false
if arrayxmiddle keyfound true;
cout
The key exists.";
else
if arrayxmiddle key
low middle ;
else
high middle ;
middle high low ;
return found;
if found false
cout "The key does not exist ;
else
cout "The key exists";
Please disregard brackets and other small syntax errors because the copying messed with the code.
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
