Java Reference
In-Depth Information
LISTING 20-3
An outline of the class SortedVectorDictionary
import java.util.Vector;
import java.util.Iterator;
import java.util.NoSuchElementException;
/**
A class that implements a dictionary by using a sorted vector.
@author Frank M. Carrano
*/
public class SortedVectorDictionary<K extends Comparable<? super K>, V>
implements DictionaryInterface<K, V>
{
private Vector<Entry> dictionary;
public SortedVectorDictionary()
{
dictionary = new Vector<Entry>(); // doubles in size, as necessary
} // end default constructor
public SortedVectorDictionary( int initialCapacity)
{
dictionary = new Vector<Entry>(initialCapacity);
} // end constructor
< Implementations of methods in DictionaryInterface >
< Private classes KeyIterator and ValueIterator (See Segment 20.20) >
private class Entry
{
private K key;
private V value;
private Entry(K searchKey, V dataValue)
{
key = searchKey;
value = dataValue;
} // end constructor
private K getKey()
{
return key;
} // end getKey
Search WWH ::




Custom Search