Inorder Tree Traversal without Recursion
Algorithm:
- Create a Stack
stack.push (node)
- Move node to left i.e. node = node.left
- Iterate till node is not null or stack is not empty
- if node is null then
node = stack.pop
- Print node
node = node.right
- Else
stack.push (node)
- node = ndoe.left
- if node is null then
Latest Source Code:
Github: BinaryTreeInOrderTraversalWithoutRecursion.java
Output:
1 / \ / \ / \ / \ / \ / \ / \ / \ 2 3 / \ / \ / \ / \ 4 5 / / / / 8 6 \ 7 8 4 2 6 7 5 1 3