I am getting a issue that my method is only returning the root node only as string. While it print the post order properly if i print the node in the helperPostOrder method.
public String postorder()
{
return helperPostOrder(root, ""); // method calling
}
private String helperPostOrder(Node root , String s){
if(root != null)
{
if(hasLeft(root)){
helperPostOrder(root.left, s);
}
if(hasRight(root)){
helperPostOrder(root.right, s);
}
s = s + " " + root;
}
return s;
}
helperPostOrder(root.left, s);is not modifyings, the value you are going to return. This is probably why you method is returning the root value without the left and right subtrees.