Commonly asked Data Structures and Algorithms Problems by big tech and different solution approaches with code in Java and C

Powered by Blogger.

Wednesday, January 3, 2018

Count Non Leaf Node Tree


int countNonLeafNodes(Node* root)
{
    int c=1;
    if(root==NULL || (root->left==NULL && root->right==NULL))
    return 0;
    c+=countNonLeafNodes(root->left);
    c+=countNonLeafNodes(root->right);
    return c;
}

0 Comments:

Post a Comment

Stats