[Tutor] drive size

alan.gauld@bt.com alan.gauld@bt.com
Mon Feb 3 12:30:01 2003


> Especially since the traditional way is to use pointers. I don't know
> the pythonic way of doing trees.

Python variables are referemces so think of them as pointers without 
the dereferencing mess.

class TreeNode:
  def __init__(self, data, left, right):
     self.data = data
     self.left = left
     self.right = right

base1 = TreeNode(1,None,None)
base2 = TreeNode(2,None,None)
node = TreeNode(3,base1,base2)

print node.data
print node.left.data
print node.right.data

I leave the rest as an excercise for the reader! :-)

Alan g.
Author of the Learn to Program website
http://www.freenetpages.co.uk/hp/alan.gauld/