I need to do a non-recursive function for count the leafs in a tree. I have the recursive algorithm, Can someone help me to figure this out!!

count leafs

int count_Lnodes(root, int cnt)
{
    if (root != NULL) 
    {
        cnt = count_Lnodes(root->left, cnt);
        cnt = count_Lnodes(root->right, cnt);
        if (root->left == NULL && root->right == NULL) ++cnt;
    }
    return cnt;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.