thx for the hint!
concerning the accurency of my algos it is just because i dont know how to use the recrsion very well yet :)!
i' ve come up with this one for counting the leaves i hope it will be fine!
- int CountLeaves(Tree *root){
-
int count;
-
if (root == NULL) return 0;
-
else{
-
CountLeaves(root -> left);
-
countLeaves(root -> right);
-
count++;
-
}
-
}
If the root is NULL you return 0 (zero) otherwise you don't return anything and
you discard the return values from your two recursive function calls.
The number of leaves is either 0 when the tree is empty, 1 when the tree is a
leaf itself, otherwise it's the number of leaves in the left subtree plus the
number of leaves in the right subtree.
hint: try to write that function without the 'count' variable; you don't need it.
kind regards,
Jos