I tried to implement delete a node in a BST. And here is my partial code.
def delete(node,key):
#Locate that node with value k
cNode=node
target=None
while cNode:
if cNode.value==key:
target=cNode
break
elif node.value>key:
cNode=cNode.lChild
elif node.value<key:
cNode=cNode.rChild
target=None
return node
When I tried to use the above method to delete a leaf node. I failed. when the method return, it did nothing to original BST. So what's the problem of this code? I assume it should have something about how python pass arguments by reference? But I am confused now. Many thanks in advance.
deletefunction, you set that to None.