I have a simple program above that creates a BST from a sorted array. It should parse the tree without showing the leaves which are essentially None. Could someone help explain why the program still spits out 'None'. I'm a python NooB and would appreciate any help.I have tried != 'None' along with is None but get the same results.
class Node:
def __init__(self,value):
self.value=value
self.nodeleft=None
self.noderight=None
def makeBST(ia,start,end,tree):
if (end < start):
return None
mid = (start + end) / 2
n = Node(ia[mid])
n.nodeleft = makeBST(ia, start, mid-1, tree)
n.noderight = makeBST(ia, mid+1, end, tree)
tree.append(n)
return n
def printBST(root):
print 'RR' ,root.value
if root.nodeleft == None:
print 'EOT'
else:
print printBST(root.nodeleft)
if root.noderight == None:
print 'EOT'
else:
print printBST(root.noderight)
if __name__ == '__main__':
array = [1, 2, 3, 4, 5, 6]
dic = []
root = makeBST(array, 0, len(array)-1, dic)
printBST(root)