Question: Write a method size that returns the total number of nodes in the tree. For example, the following tree has a size of 8: +---+
Write a method size that returns the total number of nodes in the tree. For example, the following tree has a size of 8:
+---+ | 6 | ___ +---+ ___ / \ +---+ +---+ | 3 | | 2 | +---+ +---+ / \ / \ +---+ +---+ +---+ +---+ | 1 | | 4 | | 6 | | 4 | +---+ +---+ +---+ +---+ \ +---+ | 0 | +---+
Assume that you are adding this method to the IntTree class as defined below:
public class IntTree{
private IntTreeNode overallRoot; //null for an empty tree
.........
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
