Binary Tree Inorder Traversal

EasyTrees
Next
TreeStackDFS

Print the inorder traversal of a binary tree (left subtree, node, right subtree). Do it iteratively with an explicit stack instead of recursion. Build the tree from the level-order input yourself, then solve the problem.

Input

A single line giving the tree in level order, with the word null for a missing child (for example 3 9 20 null null 15 7).

Output

Print the node values in inorder, separated by spaces.

Constraints

1 <= number of nodes <= 2000

Example 1
Input
1 null 2 3
Output
1 3 2

Inorder visits 1, then the left child of 2 (which is 3), then 2.

Hints

Binary Tree Inorder Traversal - Easy Trees Problem | Skill Shiksha