Question: /*Book *getBookByTitle(const char *title, Book *rt)--this function takes a book title as a character array, and a pointer to the root of a sub-tree as
/*Book *getBookByTitle(const char *title, Book *rt)--this function takes a book title as a character array,
and a pointer to the root of a sub-tree as its' two arguments.
It will then locate this book in the tree of books and return a pointer to the book.
If the book was not found it shall return NULL.
This must be a variation on the recursive traversal of a binary tree algorithm.
You may assume, in this case, that it is OK to return a pointer to a book in the tree without worrying about it giving access to other items in the tree.*/
Book* Library:: getBookByTitle(const char *title, Book *rt)
{
Can you help to use recursive traversal to move to each node in a binary tree and compare title given by a user?
If Found in the tree then return Found and return a pointer to the book.
If the book was not found it shall return NULL.
}
Main program(Function):
bk = lib->getBookByTitle("Quidditch Through the Ages");
if((bk != NULL) && (strcmp(bk->Title,"Quidditch Through the Ages")==0))
{
cout<<"Search successful "<<"Found Node with Title "<<"["< } else { cout<<"Search unsuccessful"< }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
