You are asked to implement the following recursive function: TNode* addLayer( TNode *root, int val ) Here's the definiti

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

You are asked to implement the following recursive function: TNode* addLayer( TNode *root, int val ) Here's the definiti

Post by answerhappygod »

You Are Asked To Implement The Following Recursive Function Tnode Addlayer Tnode Root Int Val Here S The Definiti 1
You Are Asked To Implement The Following Recursive Function Tnode Addlayer Tnode Root Int Val Here S The Definiti 1 (84.86 KiB) Viewed 33 times
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; 1/Put val in here for your new tNodes struct TNode *left, right; } TNode; 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 42 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, erit, and addLayer. TNode* addLayer( TNode *root, int val ) { 1/Declare any local variables you need //Base case: //Recursive case: (be sure to use the return value from the rec calls) : 1/Return the TMode* 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