Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 on each level. (left_view()/right_view)

image text in transcribed

8 9 typedef struct TreeNode { 10 int key; 11 int val; 12 bool flag; 13 int num_children; 14 TreeNode **children; 15 } TreeNode; 16 17 class Tree { 18 protected: 19 TreeNode* root; 20 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

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

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

Students also viewed these Databases questions

Question

In an Excel Pivot Table, how is a Fact/Measure Column repeated?

Answered: 1 week ago