Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

12.12 NVCC Lab: Count values in a tree Please refer to the TreeNode.java and MyTree.java and implement the method as specified below: public int countAboveBenchmark(MyTree

12.12 NVCC Lab: Count values in a tree

Please refer to the TreeNode.java and MyTree.java and implement the method as specified below:

public int countAboveBenchmark(MyTree mt, int val)

This method takes a MyTree and a benchmark value (val) as parameters and count and return how many numbers in the tree are greater than or equals to the benchmark value.

For example, given the following tree,

 ___[15] / \ [9] [24] / \ [3] [12] /[0]

calling: countAboveBenchmark(mt, 13) should return 2, because there are two numbers: 15 and 24 are greater than 13

=======TreeNode.java=======public class TreeNode implements Comparable{ private int data; private TreeNode left; private TreeNode right; public TreeNode(int data){ this.data=data; left=right=null; } public int getData(){ return data; } public TreeNode getLeft(){ return left; } public TreeNode getRight(){ return right; } public void setData(int data){ this.data = data; } public void setLeft(TreeNode left){ this.left = left; } public void setRight(TreeNode right){ this.right = right; } public int compareTo(TreeNode node){ return data-node.getData(); }}=========MyTree.java=======public class MyTree{ private TreeNode root; public MyTree(){ root=null; } public TreeNode getRoot(){ return root; } //all other methods are omitted}
image text in transcribed
LAB ACTIVITY 12.12.1: NVCC Lab: Count values in a tree 0 / 14 Main.java Load default template... public class Main{ public int countAboveBenchmark(MyTree mt, int val){ //TO DO: count and return how many numbers in the tree are greater than or equals to the benchmark value

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

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions

Question

Is a green economy possible?

Answered: 1 week ago