Question: #include using namespace std; class Node { private: int val; Node* left; Node* right; public: Node(); Node(int); ~Node(); bool set_val(int); bool set_left(Node*); bool set_right(Node*); int

#includeusing namespace std; class Node { private: int val; Node* left; Node* right; public: Node(); Node(int); ~Node(); bool set_val(int); bool set_left(Node*); bool set_right(Node*); int get_val(); Node* get_left(); Node* get_right(); void display(); }; Node::Node() { val=0; left=NULL; right=NULL; } Node::Node(int v) { val=v; left=NULL; right=NULL; } Node::~Node() { } bool Node::set_val(int v) { val=v; return true; } int Node::get_val() { return val; } bool Node::set_left(Node* n) { left=n; } Node* Node::get_left() { return left; } bool Node::set_right(Node* p) { right=p; } Node* Node::get_right() { return right; } void Node::display() { cout get_left()); cleanUp(curr->get_right()); cout get_val() get_left()); cout get_val() get_right()); } void BST::postorder(Node* curr) { if (curr==NULL) return; postorder(curr->get_left()); postorder(curr->get_right()); cout get_val() get_val() get_left()); preorder(curr->get_right()); } BST::BST() { root=NULL; } bool BST::add(int v) { if (is_present(v)) return false; Node* temp=new Node(v); if (root==NULL) { root=temp; return true; } Node* curr=root; while(curr!=NULL) { if (v>curr->get_val()) { if (curr->get_right()==NULL) { curr->set_right(temp); return true; } else curr=curr->get_right(); } else { if (curr->get_left()==NULL) { curr->set_left(temp); return true; } curr=curr->get_left(); } } } bool BST::is_present(int v) { Node* curr=root; while(curr!=NULL) { if (curr->get_val()==v) return true; else if (v>curr->get_val()) curr=curr->get_right(); else curr=curr->get_left(); } return false; } int main() { BST b; b.add(100); b.add(90); b.add(150); b.add(80); b.add(95); b.add(125); b.add(175); b.add(120); b.add(127); b.add(160); b.add(200); // for (int i=0;i Problem 1 (10 points) For this assignment, build on the BST code posted today (Nov 15). Support the following operations: (1) (1 point) A parameterized constructor that initializes the tree to a valid user-specified capacity. You will need to update the add function to ensure that you do not surpass the tree's capacity. (2) (2 points) A copy constructor. (3) (2 points) Overloaded assignment operator. (4) (2 points) Overloaded-= operator. Two trees are equal if they contain the exact same elements. (5) (2 points) A get_sibling class function that takes a number as input and returns its sibling. Suppose 100 is a parent, and 50 is its left child and 200 is its right child. The sibling of 50 is 200 (because 50 and 200 are the children of 100). The function assumes that the input value exists in the tree and that a sibling exists for the input value. (6) (1 point) Use const keyword as appropriate for class functions and class function inputs, including for those that we have already implemented. Demonstrate that your code works using a main function
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
