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
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
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
Functionint 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: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