public class BinarySearchST<Key extends java.lang.Comparable<Key>,Value> extends java.lang.Object
For additional documentation, see Section 3.1 of "Algorithms, 4th Edition" (p.378 of paper edition), by Robert Sedgewick and Kevin Wayne.
Constructor and Description |
---|
BinarySearchST()
Costructor.
|
BinarySearchST(int capacity)
Costructor.
|
Modifier and Type | Method and Description |
---|---|
Key |
ceiling(Key key)
Returns the smallest key that is
greater than or equal to the given key.
|
boolean |
contains(Key key)
Is the key in this symbol table?
|
void |
delete(Key key)
Remove key (and the corresponding value) from this symbol table.
|
void |
deleteMax()
Delete the maximum key and its associated value
from this symbol table.
|
void |
deleteMin()
Delete the minimum key and its associated value
from this symbol table.
|
Key |
floor(Key key)
Returns the greatest key that is
smaller than or equal to the given key.
|
Value |
get(Key key)
Returns the value associated with the given key,
or null if no such key.
|
boolean |
isEmpty()
Is this symbol table empty?
|
java.lang.Iterable<Key> |
keys()
Returns an iterable queue containing all keys
in this symbol table.
|
java.lang.Iterable<Key> |
keys(Key lo,
Key hi)
Returns an iterable queue containing all keys
of this symbol table that belong to the closed interval [lo, hi].
|
static void |
main(java.lang.String[] args)
Test client.
|
Key |
max()
Returns the greatest key in this table.
|
Key |
min()
Returns the smallest key in this table.
|
void |
put(Key key,
Value val)
Search for key in this symbol table.
|
int |
rank(Key key)
Returns the number of keys in the table
that are strictly smaller than the given key.
|
Key |
select(int k)
Returns a key that is strictly greater than
(exactly) k other keys in the table.
|
int |
size()
Returns the number of (key,value) pairs in this symbol table.
|
int |
size(Key lo,
Key hi)
Number of keys in the closed interval [lo, hi].
|
public BinarySearchST()
public BinarySearchST(int capacity)
public boolean contains(Key key)
public int size()
public boolean isEmpty()
public Value get(Key key)
public int rank(Key key)
public void put(Key key, Value val)
public void delete(Key key)
public void deleteMin()
public void deleteMax()
public Key min()
public Key max()
public Key select(int k)
public Key floor(Key key)
public Key ceiling(Key key)
public int size(Key lo, Key hi)
public java.lang.Iterable<Key> keys()
public java.lang.Iterable<Key> keys(Key lo, Key hi)
public static void main(java.lang.String[] args)