Write a recursive function to count the number of leaf nodes in the binary tree pointed at by root
. You must use the isLeaf
method to...
X326: Binary Tree Leaf Nodes Count Exercise (Modified)
Write a recursive function to count the number of leaf nodes
in the binary tree pointed at by root
.
You must use the isLeaf
method to check if a node is a
leaf, rather than check the value of the left and right
child pointers.
Here are methods that you can use on the BinNode
objects:
interface BinNode {
public int value();
public void setValue(int v);
public BinNode left();
public BinNode right();
public boolean isLeaf();
}
Your Answer:
Feedback
Your feedback will appear here when you check your answer.