Traversing in binary tree
int countLeafNodes(Node root)
{
if(root==null)
return 0;
Stack<Node> stack=new Stack<>();
stack.push(root);
int leafcount=0;
while(!stack.isEmpty())
{
Node current=stack.pop();
if(current.left==null && current.right==null)
leafcount++;
if(current.right!=null)
stack.push(current.right);
if(current.left!=null)
stack.push(current.right);
}
return leafcount;
}