Question: / Q6: Remove Book (15 points) // This function will be used to remove a book from the list. // Traverse the list and use
/ Q6: Remove Book (15 points) // This function will be used to remove a book from the list.
// Traverse the list and use the parameters to remove the book.
// You must remove all the elements in the buys linked list.
void remove_book(string title, string author)
{ Container *temp = list; Container *temp2 = list; Buy *tempPlace;
if (list->book->getTitle() == title && list->book->getAuthor() == author)
{ while(list->book->buys != NULL)
{ tempPlace = list->book->buys;
list->book->buys = list->book->buys->next;
delete(tempPlace); } list = list->next;
delete(temp->book); delete(temp); }
else
{ temp = list->next;
while (temp2->next != NULL)
{ if (temp->book->getTitle().compare(title) == 0)
{ while (temp->book->buys != NULL)
{ tempPlace = temp->book->buys;
temp->book->buys = temp->book->buys->next; delete(tempPlace); }
temp2->next = temp->next;
delete(temp->book);
delete(temp); break; }
temp2 = temp;
temp = temp->next; }
} }
Can someone help me make this code recursive please?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
