Created
November 11, 2013 15:18
-
-
Save cjrieck/7414733 to your computer and use it in GitHub Desktop.
Python tree traversals - inorder, preorder, postorder
This file contains 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 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