Question: C++ Please! Submit your class in it's own plain-text header file named Tree.h. Using the following UML class diagram, write a class that implements a

C++ Please!

Submit your class in it's own plain-text header file named Tree.h.

Using the following UML class diagram, write a class that implements a binary search tree. The binary search tree will store information for a simple phone book. Each node in the tree stores a name and a phone number. The nodes are sorted based on the name field of each node.

C++ Please! Submit your class in it's own plain-text header file named

The class has the following attributes :

Node - a nested struct that stores the information for each phone book entry. Should be private.

root- a Node pointer that stores the memory address of the root Node.

Tree - the constructor. Initializes root to nullptr.

~Tree - destructor. Frees all nodes in the tree.

isFull - returns true if there aren't enough resources to create a new tree, false otherwise.

isEmpty - returns true if the tree is empty.

insert - public version. accepts a name and phone number as string arguments. Passes them to the private, recursive version. Returns 0 if successful, -1 otherwise.

insert - private, recursive version. accepts a Node memory address, name, and phone number strings as arguments. Inserts the node into the tree. The memory address is accepted by reference.

find - public version. accepts a name as a string argument. Returns the phone string if found, or the string "NOT FOUND" otherwise.

find - private, recursive version. accepts a Node memory address and name as it's arguments. Returns the phone string if found, an empty string( "") otherwise.

clear - public version. Calls the private, recursive version, passing it the root pointer. Then sets root to nullptr.

clear - private version. Accepts the root pointer as it's only argument. Recursively destroys the list.

remove - public version. accepts a name as a string argument. Calls the private version, passing the root pointer and name string as arguments. Returns 0 if a Node was removed, -1 otherwise.

remove - private version. accepts name and root pointer as it's arguments. Accepts reoot pointer by reference. Attempts to remove the Node from the tree. Returns 0 if successful, -1 otherwise.

print - private version. accepts the root pointer as it's only argument. Recursively displays the contents of the tree using the inline traversal algorithm.

print - The public version of print accepts no arguments and simply calls the private version, passing it the root pointer.

#include "Tree.h" #include using namespace std; int main() { Tree t; t.insert("John", "510-555-1234"); t.insert("Mary", "510-555-7924"); t.insert("Rick", "510-555-4995"); t.insert("Tom", "510-555-3737"); t.insert("Pam", "510-555-8686"); t.insert("Flynn", "510-555-6837"); t.print(); cout   Tree Node name: string phone: string left: Node right: Node -root: Node -insert(r.Node*&, n:string, p:string):voic -find (r:Node*, n:string):string -clear(r Node*):void remove(r:Node%, n:string):int -print(r.Node*):void +Tree(): +-Tree); +isFull): bool +isEmpty): bool tinsert(n:string, p:string): int +find(n:string): string +clear): void +remove (n:string): int +print): void

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!