Skip to content

Commit 9226300

Browse files
committed
Added Treap class and test for the same
1 parent bece8c6 commit 9226300

File tree

2 files changed

+10
-10
lines changed
  • src
    • main/java/com/thealgorithms/datastructures/trees
    • test/java/com/thealgorithms/datastructures/trees

2 files changed

+10
-10
lines changed

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

+8-8
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ public class TreapNode {
1616
/**
1717
* TreapNode class defines the individual nodes in the Treap
1818
*
19-
* value -> holds the value of the node.
19+
* value -> holds the value of the node.
2020
* Binary Search Tree is built based on value.
2121
*
22-
* priority -> holds the priority of the node.
22+
* priority -> holds the priority of the node.
2323
* Heaps are maintained based on priority.
2424
* It is randomly assigned
2525
*
@@ -125,7 +125,7 @@ private TreapNode[] split(TreapNode node, int key) {
125125

126126
/**
127127
* insert a node into the Treap
128-
*
128+
*
129129
* @param value value to be inserted into the Treap
130130
* @return root of the Treap where the value is inserted
131131
*/
@@ -174,7 +174,7 @@ private TreapNode deleteNode(TreapNode root, int value) {
174174

175175
if (root != null) root.updateSize();
176176
return root;
177-
}
177+
}
178178

179179
/**
180180
* print inorder traversal of the Treap
@@ -226,7 +226,7 @@ private void printPostOrder(TreapNode root) {
226226

227227
/**
228228
* Search a value in the Treap
229-
*
229+
*
230230
* @param value value to be searched for
231231
* @return node containing the value
232232
* null if not found
@@ -238,11 +238,11 @@ public TreapNode search(int value) {
238238
private TreapNode searchVal(TreapNode root, int value) {
239239
if (root == null) return null;
240240

241-
if (root.value == value)
241+
if (root.value == value)
242242
return root;
243-
else if(root.value < value)
243+
else if(root.value < value)
244244
return searchVal(root.right, value);
245-
else
245+
else
246246
return searchVal(root.left, value);
247247
}
248248

src/test/java/com/thealgorithms/datastructures/trees/TreapTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ void lowerBound() {
5252
assertEquals(5, treap.lowerBound(4));
5353
}
5454

55-
@Test
55+
@Test
5656
void upperBound() {
5757
int[] arr = {5, 9, 6, 2, 3, 8, 1};
5858
Treap treap = new Treap(arr);
5959
assertEquals(6, treap.upperBound(5));
6060
}
6161

62-
@Test
62+
@Test
6363
void misc() {
6464
int[] arr = {5, 9, 6, 2, 3, 8, 1};
6565
Treap treap = new Treap(arr);

0 commit comments

Comments
 (0)