Question: JAVA 15. Suppose IntBTNode is a BTNode (from Chapter 9) with integer data. Write a new static method of the IntBTNode class to meet the

JAVA

15. Suppose IntBTNode is a BTNode (from Chapter 9) with integer data. Write a new static method of the IntBTNode class to meet the following specification. public static int count42(IntBTNode root) // Precondition: root is the root reference of a binary tree (but // NOT NECESSARILY a search tree). // Postcondition: The return value indicates how many times 42 appears // in the tree. NOTE: If the tree is empty, the method returns zero.

18. Suppose IntBTNode is a BTNode (from Chapter 9) with integer data. Write a new static method of the IntBTNode class to meet the following specification. public static int sum(IntBTNode root) // Precondition: root is the root reference of a binary tree. // Postcondition: The return value is the sum of all the data in all the nodes. // NOTES: The return value for the empty tree is zero.

22. Suppose IntBTNode is a BTNode (from Chapter 9) with integer data. Write a new static method of the IntBTNode class to meet the following specification. Make the method as efficient as possible (do not visit nodes unnecessarily). void insert42(BTNode root) // Precondition: root is the root reference of a binary SEARCH tree. // Postcondition: One copy of the number 42 has been added to the binary // search tree.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!