Skip to content

Instantly share code, notes, and snippets.

Created November 28, 2012 18:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/4163045 to your computer and use it in GitHub Desktop.
Save anonymous/4163045 to your computer and use it in GitHub Desktop.
class Tree(object):
def __init__(self, cargo, left=None, right=None):
self.cargo = cargo
self.left = left
self.right = right
def __str__(self):
return str(self.cargo)
#Traversing threw the tree
def total(tree):
if tree == None: return 0
return total(tree.left) + total(tree.right) + tree.cargo
#Allocating the child nodes
#left = Tree(2)
#right = Tree(3)
tree = Tree(1, Tree(2), Tree(3))
print total(tree)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment