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