Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In java: Write a method named sum that returns the sum of the data values stored in a binary tree. Your method accepts as its

In java:

Write a method named sum that returns the sum of the data values stored in a binary tree. Your method accepts as its parameter a TreeNode that refers to the root of the tree. For example, the following tree has a sum of 33, so if a variable named tree refers to its root, the call of sum(tree) should return 33.

 _____________3 / \ -9____ 15 / \ \ 12 24 0 / \ 3 -9 / \ 0 -6

Assume that you are interacting with TreeNodes as defined below:

public class TreeNode {
 public int data;
 public TreeNode left;
 public TreeNode right;
 
 public TreeNode() { ... }
 public TreeNode(int data) { ... }
 public TreeNode(int data, TreeNode left, TreeNode right) { ... }
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft Visual Basic 2005 For Windows Mobile Web Office And Database Applications Comprehensive

Authors: Gary B. Shelly, Thomas J. Cashman, Corinne Hoisington

1st Edition

0619254823, 978-0619254827

More Books

Students also viewed these Databases questions