Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ BINARY TREE CLASS The BinaryTree.h file wll contain your class specification for class named BinaryTree, which is an implementation of a Binary Search Tree.

C++

image text in transcribed

BINARY TREE CLASS The BinaryTree.h file wll contain your class specification for class named BinaryTree, which is an implementation of a Binary Search Tree. The BinaryTree.cpp file wil contain your class implementation for the BinaryTree class. ATTRIBUTES Instead of each tree node containing one value, your tree nodes will contain TWwO values (in addition to the left & right pointers): A string containine the name of a customer An integer containing the number of Krabby Patties the customer ate 2. You will also need a pointer to the root of the tree. CONSTRUCTOR & DESTRUCTOR You need a constructor which will set the root pointer to NULL. You will also need a destructor, which will call a private function named destroySubTree. The destroySubTree function should delete all nodes in the tree since they were dynamically allocated. BINARY TREE OPERATIONS: a new node (requires two functions) a. The public function (insertNode) should accept a new customers name and the number of Krabby Patties they ate. 1. This function should create a new TreeNode and fill it with these new values and then call the private function (insert) The insert function (recursive function) inserts the node in the correct position. b. 2. Delete a node (requires three functions) a. The public function (remove) accepts a customer's name in order to identify the node that should be removed This function prints, "You are trying to delete [namel." This function will call the private deleteNode function (a recursive function). The deleteNode function tries to find the node that needs deleted. If deleteNode finds the node, It calls the private makeDeletion function. If deleteNode does not find the node, it should print "I'm sorry. That customer can't be found in the Krusty Krab." b. c. The makeDeletion function removes the node and reattaches the branches of the tree below the node 3. (requires two functions) The public function (displaylnOrder) will call the private overloaded function also called displayinOrden The private displaylnOrder accepts a TreeNode as an argument and it is a recursive function which traverses the nodes using the inorder method and prints the customer's name from each node a. b. 4. The searchNode function accepts the customer's name as an argument and then it will look at each node (traverse the tree) to find the node with that name. If the name is found, the function returns the number of Krabby Patties that customer ate. If not, then it will return -1 instead. a. 5. Find the lowest number of Krabby Patties eaten by any customer (requires two functions] The public function (getLeastNumPatties) accepts two arguments-a string that will eventually hold the customer's name that has the least number of eaten Krabby Patties and an integer that will eventually hold the customer's # of eaten Krabby Patties. This function sets the integer parameter (leastPatties) to the root node's # of patties and then calls the private function (getLeast). The getleast function is a recursive function that traverses the nodes like the displaylnOrder function except instead of printing out the customer's name, it will check to see if the current node has a smaller number then the one saved in the leastPatties variable. If so, then save this node's customer name & number of patties as the new least. a. b. 6. number of Krabby Patties eaten by any customer (requires two functions) a. Follow the Instructions for finding the lowest except find the highest instead number of Krabby Patties eaten by ALL customers (requires two functions) The public function (eetTotalNumPatties) accepts no arguments. It reates a variable to hold the total and then calls the private getTotal function, sending the root node & the total variable (send total by reference) to the function. Then, this function will return the total as an integer The getTotal function is a recursive function that traverses the tree like the displaylnOrder function except Instead of printing out the customer's name, it will get a running total of Krabby Patties eaten from each node. a. b

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

Expert Oracle Database Architecture

Authors: Thomas Kyte, Darl Kuhn

3rd Edition

1430262990, 9781430262992

More Books

Students also viewed these Databases questions