Write a method named isFull
that returns whether or not a binary tree is full (true
if it is, false
if not).
Your method accepts as its parameter a TreeNode
that refers to the root of the tree.
A full binary tree is one in which every node has 0 or 2 children.
For example, the following tree is full:
(2 (3 (8) (7)) (1))
The following tree is not full because the 0 node has a right child but does not have a left child:
(7 (4 (9) (2)) (0 / (8)))
By definition, the empty tree is considered full.
Assume that you are interacting with TreeNode
s 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) { ... }
}