Question: How could I implement a tree using the tree node data structure as shown below, and the tree class shown below? (how would I define

How could I implement a tree using the tree node data structure as shown below, and the tree class shown below? (how would I define those functions based on what's given?)

Langauge C++

1. Max width is inputted which will be number of children each node can have (Tree(int width) )

2. Nodes are inserted based on a value and a key. They are inserted from left to right in the next open slot in the tree. (insert_node(int key, int val))

3. Delete the subtree if the subtree root's value is v (delete_node(int val))

4. Output the height of the treeumber of levels. (get_height())

5. Print the leftmost/rightmost node and each level. (left_view()/right_view)How could I implement a tree using the tree node data structure

8 9 typedef struct TreeNode { 10 int key; 11 int val; 12 bool flagi 13 int num_children; 14 TreeNode **children; 15 } TreeNode; 16 17 class Tree { 18 protected: 19 TreeNode* root; int max_width; 21 public: 22 Tree(int width); 23 int get_height(); 24 string left_view(); 25 string right_view(); 26 void insert_node(int key, int val); 27 void delete_node(int val); 28 static void solution (const char *input_path, const char *output_path); 29 30 }

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!