Binary search tree. Need to implemet the bst.cpp file. //bst.h class Node { public: int key; Node* left; Node* right; Node(int data) { key =
Binary search tree. Need to implemet 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
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
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; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started