Example: 1 / \ 2 3 ==> 4251637 / \ / \ 4 5 6 7
Left, Data, Right
1.Create a Stack
for storing the tree's nodes.
2. Start nested loops to traverse through the entire tree and its subtrees.
3. Run the outer loop infinitely and traverse the inner loop till the root becomes null.
4. Within the inner loop, push a node onto the stack
and change it to its left node.
5. Outside the inner loop, start popping the nodes from the Stack. Insert the data of the node in an ArrayList
that needs to be returned. Move to the right child.
6. If the Stack
becomes empty, break
out of the outer loop.
public ArrayList<Integer> inorderItr(TreeNode root) { }
C
Java
Python