Skip to content

Commit 50ca68f

Browse files
committed
[editing]search: RedBlack Binary Search tree
1 parent 08d94ee commit 50ca68f

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

Algorithm_full_features/search/RedBlackBST.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,43 @@ public Node(Key key, Value val, boolean color, int size) {
2525
this.size = size;
2626
}
2727
}
28+
29+
// Initializes an empty symbol table.
30+
public RedBlackBST() {
31+
//
32+
}
33+
34+
/***********************
35+
* Node helper methods *
36+
* *
37+
***********************/
38+
39+
// is node x red
40+
private boolean isRed(Node x) {
41+
if(x == null)
42+
return false;
43+
return x.color == RED;
44+
}
45+
46+
// number of node in subtree rooted at x; 0 if x is null
47+
private int size(Node x) {
48+
if(x == null)
49+
return 0;
50+
return x.size;
51+
}
52+
53+
// Returns the number of key-value pairs in this symbol table.
54+
public int size() {
55+
return size(root);
56+
}
57+
58+
public boolean isEmpty() {
59+
return root == null;
60+
}
61+
62+
/************************
63+
* Standard BST search. *
64+
* *
65+
************************/
66+
2867
}

0 commit comments

Comments
 (0)