I must write a function which takes in an tree as an argument and returns it as a string in inorder sequence.
This is what I got.
public static String concatInOrder( StringTreeNode t )
{
if(t == null) return "";
return (t.left+t.val+t.right);
}
However I've ran into several difficulties with this. Several questions.
Yes that's the correct order. The inorder
tag you added says that much.
You need to recursively call the concatInOrder
method:
public static String concatInOrder(StringTreeNode t)
{
if (t == null) return "";
return concatInOrder(t.left) + t.val + concatInOrder(t.right);
}