7.7.5. Binary Tree Leaf Nodes Count Exercise

Source
https://opendsa-server.cs.vt.edu/ODSA/Books/CS3/html/BinaryTreeInfFlw.html#binary-tree-leaf-nodes-count-exercise

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:
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
}
Function
  Base condition
  If null
    return 0
  If leaf
    return 1

 return left subtree + right subtree

Each function just does its job, and sends subtree to recursive functions