32
/ \
16 45
/ \
5 38
remove(4)
is called.Here is an interface describing a simple Dictionary ADT:
// The Dictionary Interface.
interface Dictionary<K, V> {
// Reinitialize dictionary
void clear();
// Insert a record
// k: the key for the record being inserted.
// e: the record being inserted.
void insert(K key, V value);
// Remove and return a record.
// k: the key of the record to be removed.
// Return a matching record. If multiple records match "k", remove
// an arbitrary one. Return null if no record with key "k" exists.
V remove(K key);
// Return a record matching "k" (null if none exists).
// If multiple records match, return an arbitrary one.
// k: the key of the record to find
V find(K key);
// Return the number of records in the dictionary.
int size();
};
insert | remove | find | |
---|---|---|---|
Array | |||
BST | |||
Balanced BST |