We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Tree: Postorder Traversal
- Discussions
Tree: Postorder Traversal
Tree: Postorder Traversal
Sort by
recency
|
11 Discussions
|
Please Login in order to post a comment
Java O(n)
C++ with iteration and an explicit stack. We (shallow) copy each node onto the stack. As we descend down the left or right of each node, we set their pointers to
nullptr
on the current node, so that when we return to the current node we know we've already visited them. This dovetails nicely with the leaf case, where both left and right are already null.JavaScript solution:
Python
Python 3: