I am trying to write a function that inserts a node into a binary search tree. I have seen several examples and it seems to me that my algorithm should be working, but it is failing the test for some reason.
def insert(tr, el):
""" function to insert an element into a binary search tree
following the rules of binary search trees.
return: an updated tree
precondition: assumed all elements unique
"""
if tr == None:
return createEyecuBST(el, None)
elif el < tr.value:
if tr.left == None:
tr.left = createEyecuBST(el, tr)
return tr
else: return insert(tr.left, el)
elif el > tr.value:
if tr.right == None:
tr.right = createEyecuBST(el, tr)
return tr
else: return insert(tr.right, el)
return None