Reference no: EM131003817
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
Determine the width of the slit
: Light from a sodium lamp (λ=589nm) illuminates a narrow slit and is observed on a screen 66.5 cm behind the slit. The distance between the first and third dark fringes is 7.50 mm. What is the width of the slit?
|
Show that the prepositional phrases of the nominal clause
: Show that the prepositional phrases of the nominal clause a walk on the part at noon involve both left -branching and right-branching. Come up with another nominal clause whose prepositional phrases involve both left-branching and right-branching. Di..
|
What distance between two spectral lines in first spectrum
: A light source emits two spectral lines: one at 552 nm and one at 642 nm. If the spectrum is observed using a diffraction grating with 445 line/mm and vied on a screen 2.0 m away, what is the distance between the two spectral lines in the first or..
|
Write a program to count number of inversions
: Write a Program to count number of inversions in an input file of integers using Brute force method
|
Write a recursive function sumtreenodehelper
: 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 adde..
|
Find the average velocity of the particle
: A particle moves from x = 40 cm to x = 50 cm in 5 s in one location of its path. In another location it was found that the particle moved from x = 500 cm to x = 520 cm in 2 s. Is the particle accelerating? If so, find the acceleration if the parti..
|
Call a statement in any language a computed case
: 1. We call a statement in any language a computed case type of statement if it branches to one of several areas in the program, depending on the value of a variable. Discus the positive and negative aspects of a computed case statement. In particular..
|
Autumn 2000 exam
: Data on the rates of return for two different stocks, were collected over a fifty year period. The rate of return is defined as, the increase in value of the portfolio (including any dividends or other distributions) during the year, divided by it..
|
If one person has written a component
: If one person has written a component but others have revised it, who is responsible if the component fails? What are the legal and ethical implications of reusing someone else's component?
|