Question: Write a method named size that returns the total number of nodes in a binary tree. Your method accepts as its parameter a TreeNode
Write a method named size that returns the total number of nodes 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 contains 8 nodes, so if a variable named tree refers to its root, the call of size (tree) would return 8: __6__ 1 3 } 1 2 /\ 1 46 4 1 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
a method named size that returns the total number of nodes in a binary tree The method accepts a TreeNode as its parameter which refers to the root of ... View full answer
Get step-by-step solutions from verified subject matter experts
