public class SequentialSearchST<Key,Value> extends Object
This implementation uses a singly-linked list and sequential search. It relies on the equals() method to test whether two keys are equal. It does not call either the compareTo() or hashCode() method. The put and delete operations take linear time; the get and contains operations takes linear time in the worst case. The size, and is-empty operations take constant time. Construction takes constant time.
For additional documentation, see Section 3.1 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.
| Constructor and Description |
|---|
SequentialSearchST()
Initializes an empty symbol table.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
contains(Key key)
Does this symbol table contain the given key?
|
void |
delete(Key key)
Removes the key and associated value from the symbol table
(if the key is in the symbol table).
|
Value |
get(Key key)
Returns the value associated with the given key.
|
boolean |
isEmpty()
Is this symbol table empty?
|
Iterable<Key> |
keys()
Returns all keys in the symbol table as an Iterable.
|
static void |
main(String[] args)
Unit tests the SequentialSearchST data type.
|
void |
put(Key key,
Value val)
Inserts the key-value pair into the symbol table, overwriting the old value
with the new value if the key is already in the symbol table.
|
int |
size()
Returns the number of key-value pairs in this symbol table.
|
public SequentialSearchST()
public int size()
public boolean isEmpty()
public boolean contains(Key key)
key - the keypublic Value get(Key key)
key - the keypublic void put(Key key, Value val)
key - the keyval - the valuepublic void delete(Key key)
key - the keypublic Iterable<Key> keys()
public static void main(String[] args)
Copyright © 2014. All Rights Reserved.