X287: Binary Tree Leaf Nodes Count Exercise
Write a recursive function int BTleaf(BinNode root)
to
count the number of leaf nodes in the binary tree pointed at
by root
. You must use the isLeaf()
method in the BinNode
class to check if a node is a leaf.
This is the definition of the BinNode
class:
AخA
1
interface BinNode {
2
public int value();
3
public void setValue(int v);
4
public BinNode left();
5
public BinNode right();
6
public boolean isLeaf();
7
}
Complete the BTleaf
function below.
Your Answer:
Feedback
Your feedback will appear here when you check your answer.