Write a recursive function sumTreeNodeHelper that sums the elements of a binary
ID: 3678173 • Letter: W
Question
Write a recursive function sumTreeNodeHelper that sums the elements of a binary search tree starting with the smallest element and adding elements in order up to the largest element and prints the running sum as each new value (ie. Node->val) is added to the sum (We’re assuming double values are stored in the tree).You will not use an iterator.
void sumTreeNodeHelper(struct BNode *node, double *sum) {
printf(“ Running sum = %f ”, *sum);
}
void sumTree(struct BSTree *tree, double *sum) {
sumTreeNodeHelper(tree->root, sum);
}
/* Example use */
struct BSTree myTree; int sum = 0;
/* Initialize and Add elements to the tree */
addTree(&myTree, 5); addTree(&myTree, 1);
addTree(&myTree 10); sumTree(&myTree, &sum);
printf(“ Final sum of tree values = %f ”, sum); …< /span>
The output of the above should be: Running sum = 1 Running sum = 6 Running sum = 16 Final sum of tree values = 16
Explanation / Answer
Hope this will help to you!!!!!!!!!!!!
Thank u.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.