How will you find the number of leaf nodes in a tree

Showing Answers 1 - 2 of 2 Answers

Atul Mehra

  • Nov 15th, 2006
 

FindLeafNodes(Tree *root)

{

 if (root->left == NULL && root->right == NULL)

   return 1;

else

 return (FindLeafNodes(root->left) + FindLeafNodes(root->right))

}

  Was this answer useful?  Yes

shashankjo

  • Oct 2nd, 2009
 

 
   int count=0;     // global variable

 int inorder(NODE *root)
  {
       if(root!=NULL)
       {
         inorder(root->left);
         if(root->left==NULL && root->right==NULL)
         count++;
         inorder(root->right);
        }
     return (count);
}

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions