Key
- is the property key type.Value
- is the property value type.Graph<Key,Value>
, Tree<RedBlackTreeNode<Key,Value>>
, Iterable<Key>
public class RedBlackTree<Key extends Comparable<Key>,Value> extends BinarySearchTree<RedBlackTreeNode<Key,Value>,Key,Value> implements Tree<RedBlackTreeNode<Key,Value>>
BinarySearchTree
.
see: http://algs4.cs.princeton.edu/33balanced/RedBlackBST.java.html
This implementation is not thread-safe.root
Constructor | Description |
---|---|
RedBlackTree() |
Modifier and Type | Method | Description |
---|---|---|
Key |
ceiling(Key key) |
Returns the smallest key in the symbol table greater than or equal to
key.
|
RedBlackTreeNode<Key,Value> |
ceilingNode(Key key) |
Returns the smallest key in the symbol table greater than or equal to
key.
|
void |
delete(Key key) |
Removes the specified key and its associated value from this symbol table (if
the key is in this symbol table).
|
void |
deleteMax() |
Removes the largest key and associated value from the symbol table.
|
void |
deleteMin() |
Removes the smallest key and associated value from the symbol table.
|
Key |
floor(Key key) |
Returns the largest key in the symbol table less than or equal to
key.
|
RedBlackTreeNode<Key,Value> |
floorNode(Key key) |
Returns the largest node with key in the symbol table less than or equal to
key.
|
int |
height() |
Returns the height of the BST (for debugging).
|
Iterable<Key> |
keys() |
Returns all keys in the symbol table as an Iterable.
|
Iterable<Key> |
keys(Key lo,
Key hi) |
Returns all keys in the symbol table in the given range, as an
Iterable.
|
Key |
max() |
Returns the largest key in the symbol table.
|
Key |
min() |
Returns the smallest key in the symbol table.
|
void |
put(Key key,
Value value) |
Inserts the specified key-value pair into the symbol table, overwriting the
old value with the new value if the symbol table already contains the
specified key.
|
int |
rank(Key key) |
Return the number of keys in the symbol table strictly less than
key.
|
Key |
select(int k) |
Return the kth smallest key in the symbol table.
|
int |
size() |
|
int |
size(Key low,
Key high) |
Returns the number of keys in the symbol table in the given range.
|
clear, contains, get, getRootNode, getVertices, isEmpty, iterator, iterator
getVertices
forEach, spliterator
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getRootNode
public int size()
public void put(Key key, Value value)
put
in class BinarySearchTree<RedBlackTreeNode<Key extends Comparable<Key>,Value>,Key extends Comparable<Key>,Value>
key
- the keyvalue
- the valuepublic void deleteMin()
NoSuchElementException
- if the symbol table is emptypublic void deleteMax()
NoSuchElementException
- if the symbol table is emptypublic void delete(Key key)
delete
in class BinarySearchTree<RedBlackTreeNode<Key extends Comparable<Key>,Value>,Key extends Comparable<Key>,Value>
key
- the keypublic int height()
public Key min()
NoSuchElementException
- if the symbol table is emptypublic Key max()
NoSuchElementException
- if the symbol table is emptypublic Key floor(Key key)
key
- the keyNoSuchElementException
- if there is no such keypublic RedBlackTreeNode<Key,Value> floorNode(Key key)
key
- the keyNoSuchElementException
- if there is no such keypublic Key ceiling(Key key)
key
- the keyNoSuchElementException
- if there is no such keypublic RedBlackTreeNode<Key,Value> ceilingNode(Key key)
key
- the keyNoSuchElementException
- if there is no such keypublic Key select(int k)
k
- the order statisticIllegalArgumentException
- unless k is between 0 and N − 1public int rank(Key key)
key
- the keypublic Iterable<Key> keys()
public Iterable<Key> keys(Key lo, Key hi)
lo
- is the lower border.hi
- is the upper border.Copyright © 2014–2018 PureSol Technologies. All rights reserved.