mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-12 22:56:11 +08:00
Fix bug
This commit is contained in:
@ -145,12 +145,19 @@ public class BinaryTree {
|
|||||||
successor.left.parent = successor;
|
successor.left.parent = successor;
|
||||||
|
|
||||||
//If the successor has a right child, the child's grandparent is it's new parent
|
//If the successor has a right child, the child's grandparent is it's new parent
|
||||||
if (successor.right != null && successor.parent != temp) {
|
if(successor.parent!=temp){
|
||||||
|
if(successor.right!=null){
|
||||||
successor.right.parent = successor.parent;
|
successor.right.parent = successor.parent;
|
||||||
successor.parent.left = successor.right;
|
successor.parent.left = successor.right;
|
||||||
successor.right = temp.right;
|
successor.right = temp.right;
|
||||||
successor.right.parent = successor;
|
successor.right.parent = successor;
|
||||||
|
}else{
|
||||||
|
successor.parent.left=null;
|
||||||
|
successor.right=temp.right;
|
||||||
|
successor.right.parent=successor;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (temp == root) {
|
if (temp == root) {
|
||||||
successor.parent = null;
|
successor.parent = null;
|
||||||
root = successor;
|
root = successor;
|
||||||
|
Reference in New Issue
Block a user