X510: Binary Tree Leaf Nodes Count Exercise

Write a recursive function int countBTleaves(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:

interface BinNode {
   public int value();
   public void setValue(int v);
   public BinNode left();
   public BinNode right();
   public boolean isLeaf();
}

Complete the countBTleaves method below.

Your Answer:

Reset

Practice a different Java exercise

Feedback

Your feedback will appear here when you check your answer.