Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Binary search tree. Need to complete the bst.cpp file. //bst.h class Node { publ

ID: 3804686 • Letter: B

Question

Binary search tree. Need to complete the bst.cpp file.

//bst.h

class Node {
   public:
int key;          
Node* left;  
Node* right;
Node(int data) {
       key = data;
       left = NULL;
       right = NULL;
   }
};

class BST {
public:
BST();
       ~BST();
       /* insertion */
void insert(int data);
Node* insert(Node* node, int data);
       /* search */
Node* search(int key);
Node* search(Node* node, int key);
       /* delection */
void remove(int key);
Node* remove(Node* node, int key);
Node* leftmostNode(Node* node);
       /* in-order traversal */
       void inorder();
void inorder(Node* node);
   private:
       Node* root;
};

//bst.cpp

#include <iostream>
#include "bst.h"

using namespace std;

BST::BST()
{
//////////////////
}
BST::~BST()
{
//////////////////
}
  
void BST::insert(int data) {
   //////////////////
}
Node* BST::insert(Node* node, int data) {
//////////////////
}

Node* BST::search(int key) {
   //////////////////
}
Node* BST::search(Node* node, int key) {
//////////////////
}

void BST::inorder() {
//////////////////
}
void BST::inorder(Node* node) {
//////////////////
}
      
void BST::remove(int key)
{
   //////////////////
}
Node* BST::remove(Node* node, int key)
{
//////////////////
}
Node* BST::leftmostNode(Node* node)
{
   //////////////////
}

//main.cpp

#include <iostream>
#include "bst.h"

using namespace std;

int main()
{
BST bst;
bst.insert(50);
bst.insert(30);
bst.insert(20);
bst.insert(40);
bst.insert(70);
bst.insert(60);
bst.insert(80);

bst.inorder();
cout << (bst.search(50) == NULL ? "Element not found." : "Element found.") << endl;
bst.remove(40);
bst.remove(50);
bst.inorder();
cout << (bst.search(50) == NULL ? "Element not found." : "Element found.") << endl;
return 0;
}

Explanation / Answer

Implementation (.cpp) file for a binary tree

Main file used to test the tree