Question: Develop Two Functions: 1 . void deleteTree ( BSTnode * root ) Delete an entire Binary Search Tree. 2 . void deleteNode ( BSTnode *
Develop Two Functions:
void deleteTreeBSTnode root
Delete an entire Binary Search Tree.
void deleteNodeBSTnode 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 addNodeBSTnode root int value
if root nullptr
root new BSTnode;
rootleft nullptr;
rootright nullptr;
rootdata value;
return root;
else if value rootdata
rootleft addNoderootleft, value;
return root;
else if value rootdata
rootright addNoderootright, value;
return root;
return root;
bool containsValueBSTnode root int value
if rootdata value
return true;
else if rootdata value
if rootleft nullptr
return false;
else
return containsValuerootleft,value;
else if root data value
if root right nullptr
return false;
else
return containsValuerootright, value;
return false;
BSTnode nodeSearch BSTnode root int value
if root data value
return root;
else if root data value
return nodeSearchrootleft,value;
else if root data value
return nodeSearchrootright, value;
return nullptr;
void displayBSTnode root
if root nullptr
return;
else
displayrootleft;
cout rootdata ;
displayrootright;
int main
BSTnode root nullptr;
root addNoderoot;
root addNoderoot;
root addNoderoot;
root addNoderoot;
root addNoderoot;
root addNoderoot;
root addNoderoot;
cout containsValueroot endl;
cout containsValueroot endl;
deleteNoderoot;
deleteNoderoot;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
