Question: c++ data structure 2 Binary Tree A binary tree is a data structure where all node has at most two children. Exercise: Given the code
c++ data structure
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. #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 Matrix rank calculat. CLAS Tree public: Tree() 3 bool insert(int pID, Node node) if (pID == -1) f 1 (root - NULL) { root = node; return true; ) else return false; ) return insert (PID, node, root): bool checkstring(string atr) } int charCount(char e) $ 3 private Node. Toot bool insurtint pl. Node nade. Node root) 1 Croot wwNULL) return false root-ID pio) it (root-eft hp 17 Groot->loft - NULL) root->loft - node: return true; > else if(root->right - NULL) root->right - node; return true; > olso t return false; return (pID, de, root-Sleft) lliurt(PID, noderoot->right) 2 2 hp olso { return insert (PID, node, root->left) || insert(pId, node, root->right); 3 return false; 3 }; int main() { Tree tree; Node. node1 - new Node(1, 'a'); Node node2 = new Node(2,5); Nodenode3 = new Node(3, 0); Node node4 - new Node(4,1); Node. node new Node(5. 'a'); cout 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 Matrix rank calculat. CLAS Tree public: Tree() 3 bool insert(int pID, Node node) if (pID == -1) f 1 (root - NULL) { root = node; return true; ) else return false; ) return insert (PID, node, root): bool checkstring(string atr) } int charCount(char e) $ 3 private Node. Toot bool insurtint pl. Node nade. Node root) 1 Croot wwNULL) return false root-ID pio) it (root-eft hp 17 Groot->loft - NULL) root->loft - node: return true; > else if(root->right - NULL) root->right - node; return true; > olso t return false; return (pID, de, root-Sleft) lliurt(PID, noderoot->right) 2 2 hp olso { return insert (PID, node, root->left) || insert(pId, node, root->right); 3 return false; 3 }; int main() { Tree tree; Node. node1 - new Node(1, 'a'); Node node2 = new Node(2,5); Nodenode3 = new Node(3, 0); Node node4 - new Node(4,1); Node. node new Node(5. 'a'); cout