Last active
September 15, 2015 04:00
-
-
Save kartikkukreja/04f64b6351ee592c10cb to your computer and use it in GitHub Desktop.
Inorder traversal from start
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 inorderFromStart(bst): | |
stack = [bst] | |
while bst.left is not None: | |
bst = bst.left | |
stack.append(bst) | |
while stack: | |
top = stack.pop() | |
if top.right is not None: | |
bst = top.right | |
stack.append(bst) | |
while bst.left is not None: | |
bst = bst.left | |
stack.append(bst) | |
yield top |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment