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

C++ language. Insert the following data in a BST. A BST is a tree with the follo

ID: 3767305 • Letter: C

Question

C++ language. Insert the following data in a BST. A BST is a tree with the following property. L

Explanation / Answer

struct Node { int data; Node* leftChild; Node* rightChild; Node() : leftChild(NULL), rightChild(NULL) {} }; struct BST { Node* root; BST() : root(NULL) {} void insert(int value); bool contains(int value); }; void BST::insert(int value) { Node* temp = new Node(); temp->data = value; if(root == NULL) { root = temp; return; } Node* current; current = root; Node* parent; parent = root; current = (temp->data data ? (current->leftChild) : (current->rightChild) while(current != NULL) { parent = current; current = (temp->data data) ? (current->leftChild) : (current->rightChild) } if(temp->data data) { parent->leftChild = temp; } if(temp->data > parent->data) { parent->rightChild = temp; } } bool BST::contains(int value) { Node* temp = new Node(); temp->data = value; Node* current; current = root; if(temp->data == current->data) { // base case for when node with value is found std::cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote