我试图理解删除带有两个孩子的节点的算法。我的老师写了伪代码供我们学习,但我很难理解它的某些方面。
到目前为止,我们假设我已经找到了我需要删除的节点,所以我将当前节点放在正确的位置。temp = current
tempParent = temp
temp = temp.right
while(temp.left != null)
tempParent = temp
temp = temp.left
{ //this is where i begin to get confused
tempParent.left = temp.right
temp.left = current.left
temp.right = current.right
// if we traversed until temp.left == null, how could there be a temp.left?
} // end confusion
// I understand this if statement right here
if current == parent.left
parent.left = temp
else
parent.right = temp
谢谢你们