Java icon indicating copy to clipboard operation
Java copied to clipboard

is it a bug?

Open liurongdev opened this issue 6 years ago • 2 comments

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?

liurongdev avatar Dec 27 '19 10:12 liurongdev

I think so

hdr893487191 avatar Jan 14 '20 08:01 hdr893487191

@liurongdev ,Thank for you finding the bug! I fix it in this commit.

StepfenShawn avatar Jan 26 '20 06:01 StepfenShawn