Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Principles Of Database Systems With Internet And Java Applications

Authors: Greg Riccardi

1st Edition

020161247X, 978-0201612479

More Books

Students also viewed these Databases questions

Question

3. How has Starbucks changed since its early days?

Answered: 1 week ago