class Node():
def __init__(self,data, left=None, right=None):
self.data = data
self.left = left
self.right = right
class BSTree():
def __init__(self):
self.root = None
def add(self,data):
if self.root is None:
self.root = Node(data)
self.reset()
else:
while self.curNode is not None:
if data < self.curNode.data:
self.curNode = self.curNode.left
elif data > self.curNode.data:
self.curNode = self.curNode.right
self.curNode=Node(data)
self.reset()
def pprint(self,Node,indent):
if Node is not None:
self.pprint(Node.left, indent+1)
print indent*" ",Node.data
self.pprint(Node.right, indent+1)
if __name__=="__main__":
y = BSTree()
for pres in ["OBAMA","BUSHW","CLINTON","BUSHG","REGAN","CARTER","FORD","NIXON","JOHNSON"]:
y.add(pres)
y.pprint(y.root,0)
This code runs without error but my output is
OBAMA
I cannot figure out why the code above does not have errors at runtime but only add's the first node to the tree