Thursday, February 20, 2014

Print all nodes that don’t have sibling



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