Skip to content

Instantly share code, notes, and snippets.

@kartikkukreja
Last active September 15, 2015 04:00
Show Gist options
  • Save kartikkukreja/fb053027489d2a7b55d1 to your computer and use it in GitHub Desktop.
Save kartikkukreja/fb053027489d2a7b55d1 to your computer and use it in GitHub Desktop.
Inorder traversal from end
def inorderFromEnd(bst):
stack = [bst]
while bst.right is not None:
bst = bst.right
stack.append(bst)
while stack:
top = stack.pop()
if top.left is not None:
bst = top.left
stack.append(bst)
while bst.right is not None:
bst = bst.right
stack.append(bst)
yield top
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment