Skip to content

Commit 0137b11

Browse files
committed
modified styling in if
1 parent 972d9ab commit 0137b11

File tree

1 file changed

+47
-20
lines changed
  • src/main/java/com/thealgorithms/datastructures/trees

1 file changed

+47
-20
lines changed

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

+47-20
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@ public static class TreapNode {
2929
* right -> holds the right subtree
3030
*/
3131
public int value;
32-
private int priority, size;
33-
public TreapNode left, right;
34-
35-
public TreapNode(int _value, int _priority) {
36-
value = _value;
37-
priority = _priority;
32+
private int priority;
33+
private int size;
34+
public TreapNode left;
35+
public TreapNode right;
36+
37+
public TreapNode(int valueParam, int priorityParam) {
38+
value = valueParam;
39+
priority = priorityParam;
3840
size = 1;
3941
left = right = null;
4042
}
@@ -44,8 +46,12 @@ public TreapNode(int _value, int _priority) {
4446
*/
4547
private void updateSize() {
4648
size = 1;
47-
if (left != null) size += left.size;
48-
if (right != null) size += right.size;
49+
if (left != null) {
50+
size += left.size;
51+
}
52+
if (right != null) {
53+
size += right.size;
54+
}
4955
}
5056
}
5157

@@ -74,8 +80,12 @@ public Treap() {
7480
* @return root of merged Treap
7581
*/
7682
private TreapNode merge(TreapNode left, TreapNode right) {
77-
if (left == null) return right;
78-
if (right == null) return left;
83+
if (left == null) {
84+
return right;
85+
}
86+
if (right == null) {
87+
return left;
88+
}
7989

8090
if (left.priority > right.priority) {
8191
left.right = merge(left.right, right);
@@ -158,7 +168,9 @@ public TreapNode delete(int value) {
158168
}
159169

160170
private TreapNode deleteNode(TreapNode root, int value) {
161-
if (root == null) return null;
171+
if (root == null) {
172+
return null;
173+
}
162174

163175
if (value < root.value) {
164176
root.left = deleteNode(root.left, value);
@@ -168,7 +180,9 @@ private TreapNode deleteNode(TreapNode root, int value) {
168180
root = merge(root.left, root.right);
169181
}
170182

171-
if (root != null) root.updateSize();
183+
if (root != null) {
184+
root.updateSize();
185+
}
172186
return root;
173187
}
174188

@@ -182,7 +196,9 @@ public void inOrder() {
182196
}
183197

184198
private void printInorder(TreapNode root) {
185-
if (root == null) return;
199+
if (root == null) {
200+
return;
201+
}
186202
printInorder(root.left);
187203
System.out.print(root.value + ",");
188204
printInorder(root.right);
@@ -198,7 +214,9 @@ public void preOrder() {
198214
}
199215

200216
private void printPreOrder(TreapNode root) {
201-
if (root == null) return;
217+
if (root == null) {
218+
return;
219+
}
202220
System.out.print(root.value + ",");
203221
printPreOrder(root.left);
204222
printPreOrder(root.right);
@@ -214,7 +232,9 @@ public void postOrder() {
214232
}
215233

216234
private void printPostOrder(TreapNode root) {
217-
if (root == null) return;
235+
if (root == null) {
236+
return;
237+
}
218238
printPostOrder(root.left);
219239
printPostOrder(root.right);
220240
System.out.print(root.value + ",");
@@ -232,14 +252,19 @@ public TreapNode search(int value) {
232252
}
233253

234254
private TreapNode searchVal(TreapNode root, int value) {
235-
if (root == null) return null;
255+
if (root == null) {
256+
return null;
257+
}
236258

237-
if (root.value == value)
259+
if (root.value == value) {
238260
return root;
239-
else if (root.value < value)
261+
}
262+
else if (root.value < value) {
240263
return searchVal(root.right, value);
241-
else
264+
}
265+
else {
242266
return searchVal(root.left, value);
267+
}
243268
}
244269

245270
/**
@@ -288,7 +313,9 @@ public TreapNode upperBound(int value) {
288313
* returns size of the Treap
289314
*/
290315
public int size() {
291-
if (root == null) return 0;
316+
if (root == null) {
317+
return 0;
318+
}
292319
return root.size;
293320
}
294321

0 commit comments

Comments
 (0)