Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is it a bug? #1193

Closed
liurongdev opened this issue Dec 27, 2019 · 2 comments
Closed

is it a bug? #1193

liurongdev opened this issue Dec 27, 2019 · 2 comments
Labels

Comments

@liurongdev
Copy link

liurongdev commented Dec 27, 2019

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?

@hdr893487191
Copy link

I think so

@StepfenShawn
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants