Saturday, May 14, 2011

Q. Write a program to count non leaf node in a tree?


/* Pass address of root in function argument
   count_non_leaft(root);
*/

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

0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites