Skip to content

Commit 95dc5c9

Browse files
committed
chore(fix[check-style]): use braces in if statement
1 parent 3935b05 commit 95dc5c9

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/main/java/com/thealgorithms/datastructures/trees/SplayTree.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,14 @@ private Node rotateLeft(Node x) {
120120
* @return The new root of the splayed subtree.
121121
*/
122122
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+
}
124126

125127
if (root.key > key) {
126-
if (root.left == null) return root;
128+
if (root.left == null) {
129+
return root;
130+
}
127131
// Zig-Zig case
128132
if (root.left.key > key) {
129133
// Recursive call to splay on grandchild
@@ -140,12 +144,16 @@ else if (root.left.key < key) {
140144
}
141145
return (root.left == null) ? root : rotateRight(root);
142146
} else {
143-
if (root.right == null) return root;
147+
if (root.right == null) {
148+
return root;
149+
}
144150
// Zag-Zag case
145151
if (root.right.key > key) {
146152
root.right.left = splay(root.right.left, key);
147153
// 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+
}
149157
} // Zag-Zig case
150158
else if (root.right.key < key) {
151159
root.right.right = splay(root.right.right, key);
@@ -175,7 +183,9 @@ public void insert(int key) {
175183
* @throws IllegalArgumentException If the key to be inserted already exists in the subtree.
176184
*/
177185
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+
}
179189

180190
if (key < root.key) {
181191
root.left = insertRec(root.left, key);

0 commit comments

Comments
 (0)