10 points Question 3 : Trees .. You are asked to implement the following recursive function: TNode* addLayer TNode *root

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

10 points Question 3 : Trees .. You are asked to implement the following recursive function: TNode* addLayer TNode *root

Post by answerhappygod »

10 Points Question 3 Trees You Are Asked To Implement The Following Recursive Function Tnode Addlayer Tnode Root 1
10 Points Question 3 Trees You Are Asked To Implement The Following Recursive Function Tnode Addlayer Tnode Root 1 (402.36 KiB) Viewed 41 times
10 points Question 3 : Trees .. You are asked to implement the following recursive function: TNode* addLayer TNode *root, int val ) Here's the definition of T Node struct: typedef struct tNode { int key; struct TNode *left, *right; } TNode; //Put val in here for your new TNodes This function replaces the NULLs at the bottom of the tree with new T Nodes that contain the specified val as their key. Here's an example of what it would do to a given tree: 50 50 70 NULL 70 NULL NULL 60 NULL 60 42 NULL NULL NULL NULL before addLayer( root, 42 ) 42 42 NULL NULL NULL NULL after addLayer( root, 42 ) Remember to malloc each of the new T Nodes at the bottom of the tree. If your malloc fails, your function should call exit(-1). Like we saw with inserting into a Binary Search Tree (BST), the function addLayer should return the T Node* that the parent of this T Node should point to. To help see the point of this consider the case where the root is NULL. 1337 NULL before addLayer( root, 1337 ) NULL NULL after addLayer( root, 1337 )

The only functions you should call are malloc, sizeof, exit, and addLayer. TNode* addLayer( TNode *root, int val ) { 7/Declare any local variables you need //Base case: //Recursive case: (be sure to use the return value from the rec calls) //Return the TNode* that the parent of this node should point to }
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply