Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

binary tree count number of leaves in c

/*
 Returns the count of leaf nodes in a binary tree   
*/
int countLeafNode(struct node *root){
    /* Empty(NULL) Tree */
    if(root == NULL)
        return 0;
    
    /* the cuurent node + For internal nodes, return the sum of 
    leaf nodes in left and right sub-tree */
    return (1 + countLeafNode(root->left) + countLeafNode(root->right));
}
 
PREVIOUS NEXT
Tagged: #binary #tree #count #number #leaves
ADD COMMENT
Topic
Name
5+4 =