Question: Using this struct: struct Bnode{ string data; Bnode * left; Bnode * right; }; Write a function that searches for and counts the number of

Using this struct:

struct Bnode{

string data;

Bnode * left;

Bnode * right;

};

Write a function that searches for and counts the number of times that a particular name occurs. Let the user input the name from the keyboard. (A description of the algorithm for this appears in your book on p. 523 and is printed on the reverse side of this lab paper. The output for the function should just say: Your search name appears 5 times. With the number being correct, of course.

Finally write a function that counts the number of names (not unique names) that in the tree and greater than (i.e. come after in the alphabet) the search name. This later function will work better if it is done recursively. Think of it like this:

1) If the name is less than or equal to the name in the current node add in the size of the right subtree.

2) Move to the left and repeat.

3) If the name in the current node is less than the search tree move to the right without counting anything.

4) The base case is when you hit NULL, a condition that will return a 0.

btreelab.cc below

----------------------------------------------------------

#include #include #include using namespace std; struct Bnode{ string data; Bnode * left; Bnode * right; }; void inorder(Bnode* root){ if(root != NULL){ inorder(root->left); cout<data<right); } } void add(Bnode *& root, string item){ if(root == NULL){ root=new Bnode; root->data = item; root->left=root->right=NULL; } else if (item <= root->data) add(root->left,item); else add(root->right,item); } int size(Bnode * root){ if(root == NULL) return 0; else return size(root->left) + size(root->right) + 1; } int main(){ return 0; } 

names.txt below

-----------------------------------------------

Kevin Billy William Ali Colleen Jessica Matthew Samantha Chris Benjamin Casey Meghan Evan Lydia Alex Nicholas Luke Nicholas Waylon Robert Jeffrey Zachary Hanna Dillon Nicholas Michael Robby Geoffrey Kelly Joshua Jordan Damian Samuel David David Jessie Nick Jordan Adam Spencer Joseph Matthew Dallas Samuel David Levi Jacob Austin Zachary Matthew Mick Gerrod Zachary Michael Luke Alexander Doug Anthony Aaron Andrew Charles Michael Elita Max Daniel James Shawn Shawn Sergio Tyrell Matthew Ana Abdullah Jack Brian Bo Eric Channing Kevin Hugh Serge Max Kyle Matthew Cameron Kerby Derek Paul Brandon Taffie Jacob Jacaria Christina Michael Kit Uriah Minyuan Alexander Kyle Patrick Nathan Jeromy Elaine Matthew Cody Marilyn Keenan Brady Matthew Brandon Jose Andrew Benjamin Weston Gregg Brian Sam Eric Robert Daniel Jessi Joseph Kellie Joshua Jared Kevin Jason Robbie Adam Christian Joseph Michael Zane Alex Brady Patricia Michael Kyle Joseph Joseph Jessi Daniel Nathaniel Douglas Dj Jonathan Trevor Lu Sean Michael Zach Natalie Derrick Jacob Edward Harrison Andy Justin Jared Yujia Gabriel Luke Channing Gregory Hannah Ashleigh Carson Zane Oliver Eliza Derek Levi Andrew 

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 Databases Questions!