It must print the values in the tree's inorder traversal as a single line of space-separated values.
Input Format
Our hidden tester code passes the root node of a binary tree to your_inOrder_function.
Constraints
1Nodes in the tree500
Output Format
Print the tree's inorder traversal as a single line of space-separated values.
Sample Input
1
\
2
\
5
/ \
3 6
\
4
Sample Output
1 2 3 4 5 6
Code:
"""
Node is defined as
self.left (the left child of the node)
self.right (the right child of the node)
self.data (the value of the node)
"""
def inOrder(root):
#Write your code here
stack = []
node = root
result = []
while stack or node:
if node:
stack.append(node)
node = node.left
else:
node = stack.pop()
result.append(node.data)
node = node.right
for i in result:
print(i),