Write a function that counts the number of leaf nodes in a binary tree.
Difficulty level
This exercise is mostly suitable for students
int nf_leaves(Btree B)
{
if(!B) return 0;
if(!B->left && !B->right) return 1;
return nf_leaves(B->left) + nf_leaves(B->right) ;
}
Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Modified BST