public static void printLeftPerimeter(BinaryTreeNode root, StringBuffer result)
{
if (root == null) {
return;
}
if (root.left != null) {
// System.out.print(root.data + " ");
result.append(String.valueOf(root.data) + " ");
printLeftPerimeter(root.left, result);
}
else if (root.right != null) {
//System.out.print(root.data + " ");
result.append(String.valueOf(root.data) + " ");
printLeftPerimeter(root.right, result);
}
}
why are we traversing right node as well,when we have to show only left node
can we replace code as below?
public static void traverseLeft(Node root){
if(root==null)return;
if(root.left==null && root.right==null)return;
else{
System.out.print(root.data+" ,");
traverseLeft(root.left);
}
}