Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a function named func that subtracts one from the value of each leaf node

ID: 3914469 • Letter: W

Question

Write a function named func that subtracts one from the value of each leaf node in a binary search tree. Your function should not rebalance the tree. Just subtract 1 from the leaf nodes. Note the test case output shows the in order traversal of the tree after your function is called void func (TreeNode root) struct TreeNode int key TreeNode left; TreeNode right; TreeNode xparent For example: Test Result ICreate a tree with the values 17,9,5,3 // The standard tree construction method is used After your function is called, the tree is 2578

Explanation / Answer

void func(TreeNode *root) { if(root != NULL) { if(root->left == NULL && root->right == NULL) { root->key -= 1; } else { func(root->left); func(root->right); } } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote