Number of leaves in a given binary tree

♠ Posted by GeekyFry in ,,,,,,, at 6:27 AM

Find the number of leaves in a given Binary tree

Possible solution:
1
2
3
4
5
6
int noOfLeaves(Node * t)
{
  if(t == NULL)  return 0;
  if(t->left == NULL && t->right == NULL) return 1;
  return noOfLeaves(t->left) + noOfleaves(t->right);
}

0 comments:

Post a Comment