Skip to content

Instantly share code, notes, and snippets.

@cjrieck
Created November 11, 2013 15:18
Show Gist options
  • Save cjrieck/7414733 to your computer and use it in GitHub Desktop.
Save cjrieck/7414733 to your computer and use it in GitHub Desktop.
Python tree traversals - inorder, preorder, postorder
def inorder(node):
if node.left != None:
inorder(node.left)
print node.cargo
if node.right != None:
inorder(node.right)
def preorder(node):
print node.cargo
if node.left != None:
preorder(node.left)
if node.right != None:
preorder(node.right)
def postorder(node):
if node.left != None:
postorder(node.left)
if node.right != None:
postorder(node.right)
print node.cargo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment