Java Reference
In-Depth Information
The class Entry can be private and internal to the class Dictionary , as Listing 25-3 shows.
This listing also shows Dictionary 's data field—a binary search tree—as well as the constructor
that allocates the tree. Notice how Entry is used in both the declaration and allocation of the tree.
LISTING 25-3
An outline of an implementation of the ADT dictionary that
uses a binary search tree
import TreePackage.SearchTreeInterface;
import TreePackage.BinarySearchTree;
import java.util.Iterator;
public class Dictionary<K extends Comparable<? super K>, V>
implements DictionaryInterface<K, V>
{
private SearchTreeInterface<Entry<K, V>> bst;
public Dictionary()
{
bst = new BinarySearchTree<Entry<K, V>>();
} // end default constructor
< Methods that implement dictionary operations are here. >
. . .
private class Entry<S extends Comparable<? super S>, T>
implements Comparable<Entry<S, T>>
{
private S key;
private T value;
private Entry(S searchKey, T dataValue)
{
key = searchKey;
value = dataValue;
} // end constructor
public int compareTo(Entry<S, T> other)
{
return key.compareTo(other.key);
} // end compareTo
< The class Entry also defines the methods equals , getKey , getValue , and setValue ;
no setKey method is provided. >
. . .
} // end Entry
} // end Dictionary
Search WWH ::




Custom Search