Stack<TreeNode> out_stack = new Stack<TreeNode>();
in_stack.push(root);
while (!in_stack.isEmpty()) {
TreeNode node = in_stack.pop();
out_stack.push(node);
if (node.left != null) {
in_stack.push(node.left);
}
if (node.right != null) {
in_stack.push(node.right);
}
}
while (!out_stack.isEmpty()) {
TreeNode node = out_stack.pop();
System.out.format("%d ", node.val);
}
}