#C7818. Morris Inorder Traversal
Morris Inorder Traversal
Morris Inorder Traversal
Given a binary tree, your task is to perform an inorder traversal using the Morris Traversal algorithm. This algorithm achieves O(1) space complexity by temporarily modifying the tree to avoid the use of recursion or a stack.
You will be given a binary tree in level-order format where each token is either an integer (representing a node's value) or the string null
(representing a missing node). Construct the tree accordingly, perform a Morris inorder traversal, and output the resulting sequence of node values.
Note: If the tree is empty, output an empty line.
inputFormat
A single line containing space-separated tokens representing the binary tree in level-order. Each token is either an integer or the string null
, where null
indicates that a node is absent.
outputFormat
A single line containing the inorder traversal of the binary tree as space-separated integers. If the tree is empty, output an empty line.## sample
1 null 2 3
1 3 2