Question: Please review this program that was written in C. Please let me know if it does what it is suppose to. I am looking to

Please review this program that was written in C. Please let me know if it does what it is suppose to. I am looking to see if I have errors or if I am off on my program. It looks good to me but I want some input and feedback. Thank you in advance tutor. What was the return you recieved?

#include

#include

//function declaration

int search(std::string playlist[], std::string song, int start, int end);

int main(){

//array of strings that contains a list of songs in alphabetical order

std::string playlist[] = {"A Song","Ain't No Sunshine","All You Need Is Love","Baker Street","Bad Moon Rising","Behind Blue Eyes","Billie Jean","Brown Eyed Girl","Can't Help Falling In Love"};

//string of a particular song

std::string song = "Baker Street";

//call search function and assign the returned value to a variable

int index = search(playlist, song, 0, 8);

//if index is -1, the song is not in the playlist

if(index == -1){

std::cout<

}

//if index is not -1, the song is in the playlist

else{

std::cout<

}

return 0;

}

//function definition

int search(std::string playlist[], std::string song, int start, int end){

//base case

if (start > end){

return -1;

}

//calculate the midpoint of the array

int mid = (start+end)/2;

//if the song is at the midpoint, return the index

if (song == playlist[mid]){

return mid;

}

//search left of midpoint

else if (song < playlist[mid]){

return search(playlist, song, start, mid-1);

}

//search right of midpoint

else{

return search(playlist, song, mid+1, end);

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!