static void noOfSibblings(Node root, ArrayList<Integer> l){
//Base condition
if(root == null) return;
if(root.left != null && root.right == null)
{
l.add(root.left.data);
}else if(root.left == null && root.right != null)
{
l.add(root.right.data);
}
noOfSibblings(root.left,l);
noOfSibblings(root.right,l);
}
References:
http://www.geeksforgeeks.org/print-nodes-dont-sibling-binary-tree/
No comments:
Post a Comment