public class BstDictionary
1: import TreePackage.SearchTreeInterface;
2: import TreePackage.BinarySearchTree;
3: import java.util.Iterator;
4: /**
5: A class that implements the ADT dictionary by using a binary search tree.
6: The dictionary is sorted and has distinct search keys.
7:
8: @author Frank M. Carrano
9: @author Timothy M. Henry
10: @version 5.0
11: */
12: public class BstDictionary<K extends Comparable<? super K>, V>
13: implements DictionaryInterface<K, V>
14: {
15: private SearchTreeInterface<Entry<K, V>> bst;
16:
17: public BstDictionary()
18: {
19: bst = new BinarySearchTree<>();
20: } // end default constructor
22: /* Methods that implement dictionary operations are here.
23: . . . */
25: private class Entry<S extends Comparable<? super S>, T>
26: implements Comparable<Entry<S, T>>
27: {
28: private S key;
29: private T value;
31: private Entry(S searchKey, T dataValue)
32: {
33: key = searchKey;
34: value = dataValue;
35: } // end constructor
37: public int compareTo(Entry<S, T> other)
38: {
39: return key.compareTo(other.key);
40: } // end compareTo
42: /* The class Entry also defines the methods equals, toString, getKey, getValue,
43: and setValue; no setKey method is provided.
44: . . . */
45: } // end Entry
46: } // end BstDictionary