Created
February 21, 2017 02:30
-
-
Save revanthpobala/757cf3cfc7520abae6cffb5945453f77 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def morris_tree_traversal(root): | |
current = root | |
result = [] | |
while current is not None: | |
if current.left is None: | |
result.append(current.val) | |
current = current.right | |
else: | |
pre = current.left | |
while(pre.right is not None and pre.right is not current): | |
pre = pre.right | |
if pre.right is None: | |
pre.right = current | |
current = current.left | |
else: | |
pre.right = None | |
result.append(current.val) | |
current = current.right | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment