Question: Complete the implementation of all functions in BinarySearchTree.h . main.cpp code: #include #include #include #include BinarySearchTree.h using namespace std; / / Do not modify

Complete the implementation of all functions in BinarySearchTree.h.
main.cpp code:
#include
#include
#include
#include "BinarySearchTree.h"
using namespace std;
// Do not modify the contents of this file
int main(){
BinarySearchTree tree;
tree.insert(5);
tree.insert(3);
tree.insert(4);
tree.insert(1);
tree.insert(7);
tree.draw();
BinarySearchTree backup = tree;
tree.insert(8);
tree.draw();
backup.draw();
backup.remove(backup.search(5));
backup.draw();
backup.remove(backup.search(7));
backup.draw();
return 0;
}
BinarySearchTree.h code:
#ifndef BST_H
#define BST_H
#include
struct Node{
int data;
Node* left;
Node* right;
Node(int x){
data = x;
left = nullptr;
right = nullptr;
}
};
class BinarySearchTree{
Node* root;
public:
BinarySearchTree(){
}
BinarySearchTree(const BinarySearchTree& other){
}
void insert(int x){
}
void traverse(){
}
Node* search(int x){
}
Node* min(){
}
Node* max(){
}
Node* successor(Node* start){
}
Node* findParent(Node* start){
}
void remove(Node* node){
}
// A function to display the tree graphically
void displayTree(Node* r, int level, int direction){
// Don't worry about this function, just use it
if (r != NULL){
displayTree(r->right, level+1,1);
for (int i =0; i < level-1; i++){
std::cout <<"";
}
if (level >0){
if (direction ==1){
std::cout <<"/--";
}
else{
std::cout <<"\\--";
}
}
std::cout << r->data;
std::cout << std::endl;
level++;
displayTree(r->left, level, -1);
}
}
// Call the function to display the tree and leave some space afterwards
void draw(){
displayTree(root,0,0);
std::cout << std::endl << std::endl;
}
};
#endif

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 Accounting Questions!