You are viewing a single comment's thread. Return to all comments →
Simple non-recursive solution:
void postOrder(Node root) {
Stack<Node> st1 = new Stack<Node>(); Stack<Integer> st2 = new Stack<Integer>(); st1.push(root); while (!st1.isEmpty()) { Node t = st1.pop(); st2.push(t.data); if (t.left != null) { st1.push(t.left); } if (t.right != null) { st1.push(t.right); } } //Printing the tree's postorder traversal while (!st2.isEmpty()) { System.out.print(st2.pop() + " "); }
}
Seems like cookies are disabled on this browser, please enable them to open this website
Tree: Postorder Traversal
You are viewing a single comment's thread. Return to all comments →
Simple non-recursive solution:
void postOrder(Node root) {
}