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 = %fn", *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 = %fn", sum);
...< /span>
The output of the above should be:
Running sum = 1
Running sum = 6
Running sum = 16
Final sum of tree values = 16