469,890 Members | 2,164 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,890 developers. It's quick & easy.

algorithm problem

Hi

I was trying to find an algorithm to count the number of leaf nodes in a
binary tree. I tried and could not find a nice way to do that. Can someone
give me a clue of that ?

Thanks in advance!
Nov 17 '05 #1
1 1004
struct TreeNode
{
TreeNode *left;
TreeNode *right;
int data;
};

int count(TreeNode *root)
{
if(NULL==root)
return 0;
if(root->left ==NULL && root->right==NULL)
return 1;
return count(root->left) + count(root->right);

}
"Nicole" <Ni****@discussions.microsoft.com> wrote in message
news:F4**********************************@microsof t.com...
Hi

I was trying to find an algorithm to count the number of leaf nodes in a
binary tree. I tried and could not find a nice way to do that. Can someone
give me a clue of that ?

Thanks in advance!

Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Jack Smith | last post: by
16 posts views Thread by cody | last post: by
17 posts views Thread by savesdeday | last post: by
2 posts views Thread by Sherrie Laraurens | last post: by
2 posts views Thread by Julio C. Hernandez Castro | last post: by
10 posts views Thread by Sunway | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.