New to Python. Tried implementing a BST. It works, except for the fact that I can't seem to delete nodes from it recursively:
# in class BST
def destroy(self):
if self.left:
self.left.destroy()
if self.right:
self.right.destroy()
self = None
# in main
root = BST(60)
root.insert(40) # inserts 40 at 60's left
root.insert(50) # inserts 50 at 40's right
print root.right # prints None because nothing's there
print root.left.right # prints 50
root.left.destroy() # is supposed to remove 40 and 50 from the tree
print root.left.right # prints 50, even though it should be None now...
The problem must be with the destroy()
method, but I can't see what the problem could be.