Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program that uses the binary tree definition in Figure 6.8 on page 220-222 1. Add a function to the class to count the

Write a program that uses the binary tree definition in Figure 6.8 on page 220-222 1. Add a function to the class to count the number of nodes in a binary tree 2. Add a function to the class to count the number of leaves in a binary tree YOU MUST USE THE BINARY TREE DEFINITION AS LISTED IN THE BOOK. Any other tree definition will not be accepted. Create a program that uses this class as follows (The tree is used store strings names)

1. The program should present the user with a menu as follows:

1. Add a new name 2. Delete a name 3. List the contents in ascending order 4. Display the number of nodes in the tree 5. Display the number of leafs 6. Exit the system Please enter your choice 2. Create a function for each option on the menu to handle the request. 3. For choice # 1 (Add a new value), the function should prompt the user to enter a value (a string). If the value is already stored in the tree, you should display a message that indicates that. 4. For choice # 2 (Delete a value), the function should prompt the user to enter a value (a string). Display a message to indicate if the value is found and deleted or if it is not found. 5. Main() should call a function called menu() to display the menu and return users input. Main() should not handle any input or output other than reading and validating users input.

image text in transcribed

image text in transcribed

image text in transcribed

220 Chapter 6 Binary Trees FIGURE 6.8 mplementation of a generic binary search tree. //***genBST.h ** generic binary search tree #include #include queue> using namespace std; #ifndef BINARY SEARCH TREE #de fine BINARYSEARCH TREE - templatecclass T> class Stack public stackeT> >//as in Figure 4.21 templatecclass T> class Queue public queue public: T dequeue) T tmp front O queue: :popO return tmp; void enqueue (const T&el) push (el) templatecclass T> class BSTNode public: BSTNode () left- right 0 T el; BSTNode class BST public: BSTO root-0 -BST () clear ) void clear) clear (root) root 0 bool isEmpty) const return root 0; void preorder) preorder (root) // Figure 6.11 void inorder) inorder (root) // Figure 6.11 void postorder) postorder (root) // Figure 6.11 T* search (const T& el) const return search (root,el); // Figure 6.9 void breadthFirst) void iterativePreorder void iterativeInorder void iterativePostorder) void MorrisInorder O void insert (const T&) void deleteByMerging (BSTNodeT>*&) ; // Figure 6.10 // Figure 6.15 // Figure 6.17 // Figure 6.16 // Figure 6.20 // Figure 6.23 // Figure 6.29 void findAndDeleteByMerging (const T&) i // Figure 6.29 void void deleteByCopying (BSTNodeT>*&) ; balance (T*, int,int); // Figure 6.32 // Section 6.7 protected BSTNodeeT>* root; Continues 222 Chapter 6 Binary Trees FIGURE 6.8 (continued) void clear (BSTNode*) void inorder (BSTNode*) virtual void visit (BSTNode* p) // Figure 6.11 // Figure 6.11 // Figure 6.11 cout

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Solaris 11.2 System Administration (oracle Press)

Authors: Harry Foxwell

1st Edition

007184421X, 9780071844215

More Books

Students also viewed these Databases questions

Question

The (perfect) solution is d.

Answered: 1 week ago