A node is a leaf node if both left and right child nodes of it are NULL
NumberOfLeafNodes(root);
int NumberOfLeafNodes(NODE *p)
{
NODE *nodestack[50];
int top=-1;
int count=0;
if(p==NULL)
return 0;
nodestack[++top]=p;
while(top!=-1)
{
p=nodestack[top--];
while(p!=NULL)
{
if(p->leftchild==NULL && p->rightchild==NULL)
count++;
if(p->rightchild!=NULL)
nodestack[++top]=p->rightchild;
p=p->leftchild;
}
}
return count;
}