Java
Java copied to clipboard
is it a bug?
the file java/DataStructures/Trees/BinaryTree.java maybe wrong about in remove function .
//If the successor has a right child, the child's grandparent is it's new parent
if (successor.right != null && successor.parent != temp) {
successor.right.parent = successor.parent;
successor.parent.left = successor.right;
successor.right = temp.right;
successor.right.parent = successor;
}
l think the right code is:
//If the successor has a right child, the child's grandparent is it's new parent
if(successor.parent!=temp){
if(successor.right!=null){
successor.right.parent = successor.parent;
successor.parent.left = successor.right;
successor.right = temp.right;
successor.right.parent = successor;
}else{
successor.parent.left=null;
successor.right=temp.right;
successor.right.parent=successor;
}
}
Am I thinking right?
I think so
@liurongdev ,Thank for you finding the bug! I fix it in this commit.