Write a recursive function sumtreenodehelper

Assignment Help Basic Computer Science
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

Reference no: EM131003817

Questions Cloud

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?

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Demonstrate an understanding of existing strategic impact

Demonstrate an understanding of existing and emerging information technologies and strategic impact on organizational operations. Explain how to develop reasoned responses to the major forces shaping the role of IT in organizations competing in a ..

  Make the contents of your script resident in memory

Modify your whoisthere function so that you can enter "These are the folks logged in:" as an argument to appear before your list of who is logged in to the system.

  Estate agents and an office manager in the office.

A new real estate company that would like to set up a Windows network in their office. (There is currently nothing in place.) They currently have ten real estate agents and an office manager in the office.

  A group of children play a scavenger

A group of children play a scavenger hunt under a time limit of two hours. Points are given to the amount of items found, the type of item does not matter.

  What are the benefits, drawbacks, and business

What are the benefits, drawbacks, and business impacts of RAID 1, RAID 5, and RAID 1

  Write an appropriate me expression capturing the essence

Write an appropriate ME expression capturing the essence

  Write a program segment that initializes memory locations

Write a program segment that initializes memory locations $0000 and $0001 with $12 and $10 using assembler directives.

  Container that holds the water

The container that holds the water for the football team is 3/10 full. After pouring in 11 gallons of water, it is 4/5 full. How many gallons can the container hold

  Open a new database in microsoft access

Open a new database in Microsoft Access

  Find a current news article in the ashford university

Find a current news article in the Ashford University Library's ProQuest Newsstand database about an ethical issue that involves computer technology, or involves a technology company Summarize the facts and major points from the article and be sure t..

  What purposes do cpus, memory and i-o devices

What purposes do CPUs, memory and I-O devices individually serve in a computer system

  What are two main functions of user accounts in a network

1. What are the two main functions of user accounts in a network? As a network administrator, how would you establish user rights and permissions to minimize maintenance efforts? How would you assign work groups? what are some issues with user..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd