Last active
September 15, 2015 04:00
-
-
Save kartikkukreja/fb053027489d2a7b55d1 to your computer and use it in GitHub Desktop.
Inorder traversal from end
This file contains hidden or 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 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