Question: Consider the following BST and TNode classes. template class TNode public: T val; TNode* left; TNode* right; template class BST public: BST); BST(); bool Search(T&

 Consider the following BST and TNode classes. template class TNode public:T val; TNode* left; TNode* right; template class BST public: BST); BST();

Consider the following BST and TNode classes. template class TNode public: T val; TNode* left; TNode* right; template class BST public: BST); BST(); bool Search(T& val); void Insert(T& val); int count; // stores the number of // nodes in the subtree // rooted at this node. private: TNode *root; }; int count(TNode * node) { if (node == nullptr) return; else return node->count; } }; In addition to the value, each node stores in a data member named count the number of nodes in the tree rooted at that node (see the illustration for an example). 10 count -9 5 count = 6 15 count = 2 3 count = 2 7 count = 3 20 count = 1 2 count - 1 6 count = 1 9 count = 1 What modifications need to be made to the following code for the insert function in order for the count variable to be updated correctly? Provide only the line number(s) and the modified code at these lines only (do not re-write the whole function). 1 template 2 void BST:: insert(T& val){ TNode* newNode = new TNode (val , nullptr, nullptr); What modifications need to be made to the following code for the insert function in order for the count variable to be updated correctly? Provide only the line number(s) and the modified code at these lines only (do not re-write the whole function). 1 template 2 void BST:: insert(T& val){ 3 TNode* newNode = new TNode (val , nullptr, nullptr); 4 5 6 7 if (isEmpty()) { root = newNode; return; } 8 9 10 TNode * p = nullptr; TNode * C = root; while (c != nullptr) { p = 0; 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 } if (val > C->data) C = C->right; else C = C->left; } if (val > p->data ) p->right = newNode; else p->left = newNode; Consider the following BST and TNode classes. template class TNode public: T val; TNode* left; TNode* right; template class BST public: BST); BST(); bool Search(T& val); void Insert(T& val); int count; // stores the number of // nodes in the subtree // rooted at this node. private: TNode *root; }; int count(TNode * node) { if (node == nullptr) return; else return node->count; } }; In addition to the value, each node stores in a data member named count the number of nodes in the tree rooted at that node (see the illustration for an example). 10 count -9 5 count = 6 15 count = 2 3 count = 2 7 count = 3 20 count = 1 2 count - 1 6 count = 1 9 count = 1 What modifications need to be made to the following code for the insert function in order for the count variable to be updated correctly? Provide only the line number(s) and the modified code at these lines only (do not re-write the whole function). 1 template 2 void BST:: insert(T& val){ TNode* newNode = new TNode (val , nullptr, nullptr); What modifications need to be made to the following code for the insert function in order for the count variable to be updated correctly? Provide only the line number(s) and the modified code at these lines only (do not re-write the whole function). 1 template 2 void BST:: insert(T& val){ 3 TNode* newNode = new TNode (val , nullptr, nullptr); 4 5 6 7 if (isEmpty()) { root = newNode; return; } 8 9 10 TNode * p = nullptr; TNode * C = root; while (c != nullptr) { p = 0; 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 } if (val > C->data) C = C->right; else C = C->left; } if (val > p->data ) p->right = newNode; else p->left = newNode

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