@@ -120,10 +120,14 @@ private Node rotateLeft(Node x) {
120
120
* @return The new root of the splayed subtree.
121
121
*/
122
122
private Node splay (Node root , int key ) {
123
- if (root == null || root .key == key ) return root ;
123
+ if (root == null || root .key == key ) {
124
+ return root ;
125
+ }
124
126
125
127
if (root .key > key ) {
126
- if (root .left == null ) return root ;
128
+ if (root .left == null ) {
129
+ return root ;
130
+ }
127
131
// Zig-Zig case
128
132
if (root .left .key > key ) {
129
133
// Recursive call to splay on grandchild
@@ -140,12 +144,16 @@ else if (root.left.key < key) {
140
144
}
141
145
return (root .left == null ) ? root : rotateRight (root );
142
146
} else {
143
- if (root .right == null ) return root ;
147
+ if (root .right == null ) {
148
+ return root ;
149
+ }
144
150
// Zag-Zag case
145
151
if (root .right .key > key ) {
146
152
root .right .left = splay (root .right .left , key );
147
153
// Perform zig operation on parent
148
- if (root .right .left != null ) root .right = rotateRight (root .right );
154
+ if (root .right .left != null ) {
155
+ root .right = rotateRight (root .right );
156
+ }
149
157
} // Zag-Zig case
150
158
else if (root .right .key < key ) {
151
159
root .right .right = splay (root .right .right , key );
@@ -175,7 +183,9 @@ public void insert(int key) {
175
183
* @throws IllegalArgumentException If the key to be inserted already exists in the subtree.
176
184
*/
177
185
private Node insertRec (Node root , int key ) {
178
- if (root == null ) return new Node (key );
186
+ if (root == null ) {
187
+ return new Node (key );
188
+ }
179
189
180
190
if (key < root .key ) {
181
191
root .left = insertRec (root .left , key );
0 commit comments