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

(17 pts) In this problem you will be working with a dynamically linked binary se

ID: 3732555 • Letter: #

Question

(17 pts) In this problem you will be working with a dynamically linked binary search tree (BST). Glven a class ESTNode with the following private data members: BSTNode mpLeft BSTNode *mpRight atring mtata; and the fallowing public member functions BSTNode (const string newbata) string getData) and a class BST with the follawing private data member: BSTNod Root Write an appropriate recursive inro method that is a member of the as class. The function should accept a reference to a pointer) to a eSTNode and a const reference to the data to insert The function does not need to retum a value. However, no makoNd function exists.

Explanation / Answer

bool BST::insertNode(BSTNode *&temp, const string &data) {
   if(temp != NULL) {
       if(data == temp->getData()) {
           return false;
       }
       else if(data < temp->getData()) {
           insertNode(temp->getLeft(), data);
       } else{
           insertNode(temp->getRight(), data);
       }
   } else {
       temp = new BSTNode(data);
   }
   return true;
}