I want to calculate the number of leaves in a binary search tree.
I think the code should be like this in the recursion way:
but what is the base case? It seems to be too many cases should be considered (such as "have a left subtree but no right subtree"), so the base case is not easy to write?:confused: :confused:Code:int
Leaves(Tree T)
{
int LL, RL;
.......
LL = Leaves(T->Left);
RL = Leaves(T->Right);
return LL+RL;
}