This is from another Question i just forgot to Ask for it inJava. Need this conv
ID: 3618248 • Letter: T
Question
This is from another Question i just forgot to Ask for it inJava. Need this converted to Java asap.Will rate lifesaver on first post.
Thanks, Aphareus
Edit: Thought id put in the orginal Question so you havesomeunderstanding:
(Implementing preorder without using recrusion) Implement thepreorder method in Binary Tree using a stack instead ofrecursion.
public String preorder(TreeNode root)
{
String output = "";
Stack<TreeNode> stack = newStack<TreeNode>();
if(root != null)
{
stack.push(root);
}
while(!stack.isEmpty())
{
TreeNodetemp = stack.pop();
output +=temp.getValue();
if(temp.getLeft() != null)
{
stack.push(temp.getLeft());
}
if(temp.getRight() != null)
{
stack.push(temp.getRight());
}
}
return output;
}