INNER CODE UNIT · Python
morris_traversal
AllAlgorithms/python · data-structures/InorderTreeTraversal.py:9
def morris_traversal(root):
"""Generator function for iterative inorder tree traversal"""
current = root
while current is not None:
if current.left is None:
yield current.data
current = current.right
else:
# Find the inorder predecessor of current
pre = current.left
while pre.right is not None and pre.right is not current:
pre = pre.right
if pre.right is None: