Question: Develop Two Functions: 1 . void deleteTree ( BSTnode * root ) Delete an entire Binary Search Tree. 2 . void deleteNode ( BSTnode *

Develop Two Functions:
1. void deleteTree(BSTnode *root)
Delete an entire Binary Search Tree.
2. void deleteNode(BSTnode *root, int value)
Delete a Binary Search Tree node with the given while maintaining the BST. Each node in the Binary Search Tree will have a unique value. If the value is not in the BST, print: "There is no node in the Binary Search Tree with that value." This is to be added to our code definition of BSTs in class, featured below:
#include
#include
#include
using namespace std;
struct BSTnode {
int data;
BSTnode *left;
BSTnode *right;
};
BSTnode *addNode(BSTnode *root, int value){
if (root == nullptr){
root = new BSTnode;
root->left = nullptr;
root->right = nullptr;
root->data = value;
return root;
} else if (value < root->data){
root->left = addNode(root->left, value);
return root;
} else if (value > root->data){
root->right = addNode(root->right, value);
return root;
}
return root;
}
bool containsValue(BSTnode *root, int value){
if (root->data == value){
return true;
} else if (root->data > value){
if (root->left == nullptr){
return false;
} else {
return containsValue(root->left,value);
}
} else if (root -> data < value){
if (root -> right == nullptr){
return false;
} else {
return containsValue(root->right, value);
}
}
return false;
}
BSTnode* nodeSearch (BSTnode *root, int value){
if (root -> data == value){
return root;
} else if (root -> data > value){
return nodeSearch(root->left,value);
} else if (root -> data < value){
return nodeSearch(root->right, value);
}
return nullptr;
}
void display(BSTnode *root){
if (root == nullptr){
return;
} else {
display(root->left);
cout << root->data <<"";
display(root->right);
}
}
int main(){
BSTnode *root = nullptr;
root = addNode(root,1);
root = addNode(root,3);
root = addNode(root,5);
root = addNode(root,8);
root = addNode(root,-11);
root = addNode(root,-15);
root = addNode(root,-10);
cout << containsValue(root,-15)<< endl;
cout << containsValue(root,-135)<< endl;
deleteNode(root,16);
deleteNode(root,8);
}

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!