How do you write this program in c++ language? Write a C++ program which allows
ID: 3820913 • Letter: H
Question
How do you write this program in c++ language? Write a C++ program which allows the 'showMenu()' function below to work. You should add (menu option #1) at least 5 items in the BST, before you select any other options. Run you program to show all options on the menu work correct int showMenu() {do {coutExplanation / Answer
# include # include using namespace std; struct node { int data; struct node* left; struct node* right; }*root; class BinaryTree{ public: int size(node* ); int maxDepth(node*); int minValue(node*); void printTree(node*); int ShowMenu(); bool deleteItem(node*, int target); }; struct node* NewNode(int data) { struct node* node = new(struct node); // "new" is like "malloc" node->data = data; node->left = NULL; node->right = NULL; return(node); } struct node* insert(struct node* node, int data) { // 1. If the tree is empty, return a new, single node if (node == NULL) { return(NewNode(data)); } else { // 2. Otherwise, recur down the tree if (data data) node->left = insert(node->left, data); else node->right = insert(node->right, data); return(node); // return the (unchanged) node pointer } } int BinaryTree::size(struct node* node) { if (node==NULL) { return(0); } else { return(size(node->left) + 1 + size(node->right)); } } int BinaryTree::maxDepth(struct node* node) { if (node==NULL) { return(0); } else { // compute the depth of each subtree int lDepth = maxDepth(node->left); int rDepth = maxDepth(node->right); // use the larger one if (lDepth > rDepth) return(lDepth+1); else return(rDepth+1); } } int BinaryTree::minValue(struct node* node) { struct node* current = node; // loop down to find the leftmost leaf while (current->left != NULL) { current = current->left; } return(current->data); } void BinaryTree::printTree(struct node* node) { if (node == NULL) return; printTree(node->left); cout right); } bool BinaryTree::deleteItem(struct node* node, int target) { if (node == NULL) { return(false); } else { // 2. see if found here if (target == node->data){ free(node); return(true); } else { // 3. otherwise recur down the correct subtree if (target data) return(deleteItem(node->left, target)); else return(deleteItem(node->right, target)); } } } int BinaryTree::ShowMenu(){ int selection; do{ coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.