Answered step by step
Verified Expert Solution
Question
...
1 Approved Answer
Data Members: struct Node { Type data; Node * left, * right; Node * parent; / / node Constructor goes here if implemented correctly }
Data Members: struct Node Type data; Node left, right; Node parent; node Constructor goes here if implemented correctly BST: mRoot Pointer to the root top node Methods: Node Constructor Nodeconst Type& data, Nodeparent nullptr : datadata parentparent left right nullptr; BST Constructor BST mRoot nullptr; Push void Pushconst Type& val Node newNode new Nodeval; if mRoot nullptr mRoot newNode; return; Node temp mRoot; while temp nullptr if val temp if templeft nullptr templeft newNode; break; temp templeft; else if tempright nullptr tempright newNode; break; temp tempright; Clear void Clear ClearmRoot; mRoot nullptr; Recursive helper method for use with Clear void ClearNodecurr if curr nullptr return; Clearcurrleft; Clearcurrright; delete curr; Destructor ~BST Clear; Contains bool Containsconst Type& val Node temp mRoot; while temp nullptr if val tempdata temp templeft; else if val tempdata temp tempright; else return true; value found return false; value not found FindNode Optional Node FindNodeconst Type& val Checks to see if a value is present in the tree and returns the address if found Create a temporary pointer to traverse down the tree RemoveCase void RemoveCaseNodenode Removes a node from the tree that has no children o Can assume the node passed in is a leaf node Three subcases o Root nodeo Is a left child o Is a right child RemoveCase void RemoveCaseNodenode Removes a node from the tree that has one child o Can assume the node passed in has exactly one child Six subcases o Root node with left child o Root node with right child o Left child that has a left child o Left child that has a right child o Right child that has a left child o Right child that has a right child RemoveCase void RemoveCaseNodenode Removes a node from the tree that has both children o Can assume the node passed in has both children This will ultimately lead to a Case or Case removal Remove bool Removeconst Type& val Removes a node from the tree by calling the appropriate RemoveCase method Find the address of the node to be removed Theres potentially a method for this Check to see how many children that node has, and call the appropriate RemoveCase method Return true, if something was removed InOrder std::string InOrder Creates a spacedelimited string that contains the values of the tree in ascending order Start with the root and use the recursive InOrder method to build out the string one value at a time Use std::tostring to convert the int into its string equivalent Recursive helper method to help with InOrder void InOrderNodecurr, std::string& str Implement this method Assignment Operator BST& operatorconst BST& assign Assigns all values to match those of the object passed in Clean up existing memory before the deep copy Theres a method that does this Deep copy the entire tree o Use the recursive Copy method to duplicate the tree with a preorder traversal Each recursive call to copy should create a single node by Pushing it Copy Constructor BSTconst BST& copy Assigns all values to match those of the object passed in Deep copy the entire tree o Use the recursive Copy method to duplicate the tree with a preorder traversal Each recursive call to copy should create a single node by Pushing it Remember that data members are not automatically initialized in C Recursive helper method for use with rule of void Copyconst Nodecurr Implement this method Extra instructions for what some methods should do Contains should check found and not found RemoveCase should check root, left, right, RemoveCase should check rootleft, rootright, leftleft, leftright, rightleft, rightright RemoveCase case RemoveCase case Check Remove not found Some of these I have completed, Im just a little confused about the otherss and was looking for clearer instructions on how to implement these?
Data Members:
struct Node
Type data;
Node left, right;
Node parent;
node Constructor goes here if implemented correctly
BST:
mRoot Pointer to the root top node
Methods:
Node Constructor
Nodeconst Type& data, Nodeparent nullptr : datadata parentparent
left right nullptr;
BST Constructor
BST
mRoot nullptr;
Push
void Pushconst Type& val
Node newNode new Nodeval;
if mRoot nullptr
mRoot newNode;
return;
Node temp mRoot;
while temp nullptr
if val temp
if templeft nullptr
templeft newNode;
break;
temp templeft;
else
if tempright nullptr
tempright newNode;
break;
temp tempright;
Clear
void Clear
ClearmRoot;
mRoot nullptr;
Recursive helper method for use with Clear
void ClearNodecurr
if curr nullptr
return;
Clearcurrleft;
Clearcurrright;
delete curr;
Destructor
~BST
Clear;
Contains
bool Containsconst Type& val
Node temp mRoot;
while temp nullptr
if val tempdata
temp templeft;
else if val tempdata
temp tempright;
else
return true; value found
return false; value not found
FindNode Optional
Node FindNodeconst Type& val
Checks to see if a value is present in the tree and returns the address if found
Create a temporary pointer to traverse down the tree
RemoveCase
void RemoveCaseNodenode
Removes a node from the tree that has no children
o Can assume the node passed in is a leaf node
Three subcases
o Root nodeo Is a left child
o Is a right child
RemoveCase
void RemoveCaseNodenode
Removes a node from the tree that has one child
o Can assume the node passed in has exactly one child
Six subcases
o Root node with left child
o Root node with right child
o Left child that has a left child
o Left child that has a right child
o Right child that has a left child
o Right child that has a right child
RemoveCase
void RemoveCaseNodenode
Removes a node from the tree that has both children
o Can assume the node passed in has both children
This will ultimately lead to a Case or Case removal
Remove
bool Removeconst Type& val
Removes a node from the tree by calling the appropriate RemoveCase method
Find the address of the node to be removed Theres potentially a method for this
Check to see how many children that node has, and call the appropriate RemoveCase method
Return true, if something was removed
InOrder
std::string InOrder
Creates a spacedelimited string that contains the values of the tree in ascending order
Start with the root and use the recursive InOrder method to build out the string one
value at a time
Use std::tostring to convert the int into its string equivalent
Recursive helper method to help with InOrder
void InOrderNodecurr, std::string& str
Implement this method
Assignment Operator
BST& operatorconst BST& assign
Assigns all values to match those of the object passed in
Clean up existing memory before the deep copy Theres a method that does this
Deep copy the entire tree
o Use the recursive Copy method to duplicate the tree with a preorder traversal
Each recursive call to copy should create a single node by Pushing it
Copy Constructor
BSTconst BST& copy
Assigns all values to match those of the object passed in
Deep copy the entire tree
o Use the recursive Copy method to duplicate the tree with a preorder traversal
Each recursive call to copy should create a single node by Pushing it
Remember that data members are not automatically initialized in C
Recursive helper method for use with rule of
void Copyconst Nodecurr
Implement this method
Extra instructions for what some methods should do
Contains should check found and not found
RemoveCase should check root, left, right,
RemoveCase should check rootleft, rootright, leftleft, leftright, rightleft, rightright
RemoveCase case
RemoveCase case
Check Remove not found
Some of these I have completed, Im just a little confused about the otherss and was looking for clearer instructions on how to implement these?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
![blur-text-image](https://dsd5zvtm8ll6.cloudfront.net/includes/images/document_product_info/blur-text-image.webp)
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
![blur-text-image](https://dsd5zvtm8ll6.cloudfront.net/includes/images/document_product_info/blur-subtext-image.webp)
Step: 3
![blur-text-image](https://dsd5zvtm8ll6.cloudfront.net/includes/images/document_product_info/blur-subtext-image.webp)
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started