Saturday, May 14, 2011

Q. Write a program to count leaf node in a tree using recursive function.


/*Pass address of root node in function argument...
count_leaf(root);*/


count_leaf(struct bintree *t)
{
     int c1 = 0, c2 = 0;
     if(t!=NULL)
     {
           if(t->left == NULL && t->right == NULL)
                      c1 = 1;
           c2 = retun (count_leaf(t->left)+c1);
           return (count_leaf(t->right)+c2);
     }
     return 0;
}

0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites