Question: data structure (c++) 2 Binary Tree A binary tree is a data structure where all node has at most two children. Exercise: Given the code

 data structure (c++) 2 Binary Tree A binary tree is a

data structure where all node has at most two children. Exercise: Given

data structure (c++)

2 Binary Tree A binary tree is a data structure where all node has at most two children. Exercise: Given the code of the Node struct and the insert method of the tree, implement the binary tree with the following functionalities: Tree: a constructor to initialize a tree object. checkString: returns true if a string is found in a path in the tree starting from the root to any node in the tree. Otherwise, false is returned. charCount: returns the number of a specific character in the whole tree. All cases must be handled. You can define any helper methods as needed. checkString: returns true if a string is found in a path in the tree starting from ti node in the tree. Otherwise, false is returned. charCount: returns the number of a specific character in the whole tree. All cases must be handled. You can define any helper methods as needed. #include using namespace std; struct Node { int ID; char alpha; Node* left; Node* right; Node (int ID, char alpha) { this->ID = ID; this->alpha = alpha; left = NULL; 2 right = NULL; } }; class Tree { public: Tree() { } 37 bool insert(int pID, Node* node) { if (PID == -1) { if (root == NULL) { root = node; return true; } else return false; } return insert(PID, node, root); } bool checkString (string str) { } int charCount(char c) { } private: Node* root; bool insert(int PID, Node* node, Node*& root) { if (root = NULL) return false; else if (root->ID == PID) { if(root->left == NULL) { root->left = node; return true; } else if (root->right == NULL) { root->right = node; return true; } else { return false; }

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!