@@ -72,9 +72,12 @@ public boolean remove(int value) {
72
72
if (temp == null || temp .data != value ) return false ;
73
73
74
74
if (temp .left == null && temp .right == null ) {
75
- if (temp == root ) root = null ;
76
- else if (temp .parent .data < temp .data ) temp .parent .right = null ;
77
- else temp .parent .left = null ;
75
+ if (temp == root )
76
+ root = null ;
77
+ else if (temp .parent .data < temp .data )
78
+ temp .parent .right = null ;
79
+ else
80
+ temp .parent .left = null ;
78
81
return true ;
79
82
} else if (temp .left != null && temp .right != null ) {
80
83
Node successor = findSuccessor (temp );
@@ -84,7 +87,8 @@ public boolean remove(int value) {
84
87
if (successor .right != null ) {
85
88
successor .right .parent = successor .parent ;
86
89
successor .parent .left = successor .right ;
87
- } else successor .parent .left = null ;
90
+ } else
91
+ successor .parent .left = null ;
88
92
successor .right = temp .right ;
89
93
successor .right .parent = successor ;
90
94
}
@@ -93,17 +97,22 @@ public boolean remove(int value) {
93
97
successor .parent = null ;
94
98
} else {
95
99
successor .parent = temp .parent ;
96
- if (temp .parent .data < temp .data ) temp .parent .right = successor ;
97
- else temp .parent .left = successor ;
100
+ if (temp .parent .data < temp .data )
101
+ temp .parent .right = successor ;
102
+ else
103
+ temp .parent .left = successor ;
98
104
}
99
105
return true ;
100
106
} else {
101
107
Node child = (temp .right != null ) ? temp .right : temp .left ;
102
- if (temp == root ) root = child ;
108
+ if (temp == root )
109
+ root = child ;
103
110
else {
104
111
child .parent = temp .parent ;
105
- if (temp .data < temp .parent .data ) temp .parent .left = child ;
106
- else temp .parent .right = child ;
112
+ if (temp .data < temp .parent .data )
113
+ temp .parent .left = child ;
114
+ else
115
+ temp .parent .right = child ;
107
116
}
108
117
return true ;
109
118
}
0 commit comments