Skip to content

Instantly share code, notes, and snippets.

@kartikkukreja
Last active September 15, 2015 04:00
Show Gist options
  • Save kartikkukreja/04f64b6351ee592c10cb to your computer and use it in GitHub Desktop.
Save kartikkukreja/04f64b6351ee592c10cb to your computer and use it in GitHub Desktop.
Inorder traversal from start
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