经典的数据结构作业,实现Dictionary ADT的接口,完成Latin Dictionary.
The Program
This program is an example of an application that uses a very common interface, the DictionaryADT. A dictionary is a structure that accepts key=value pairs. The keys are used to order the structure and to lookup values. Keys must be distinct; no duplicates are allowed. There may, however, be duplicate values. For this dictionary application, the key is a latin word, and the value is its definition. The application program consists of the java class LatinDictionary, which has the following methods:
1 | import java.util.Iterator; |
To assist you in developing the application, you will be provided with two helper classes, and a sample driver program:
- DictionaryReader.java This class has the static method public static DictionaryEntry[] getDictionaryArray(String fileName) This method reads a datafile with latin words and their definitions. The datafile was provided by the Internet Dictionary Project and is in the public domain. The method creates an array of type DictionaryEntry (also provided) and returns it.
- DictionaryEntry.java This class is a wrapper class that has two String fields, the KEY and VALUE. These are the latin word, and its definition. This is for convenience in getting the data into your dictionary structure. Note that you must extract the key and value from a DictionaryEntry object to insert them into your dictionary.
- DictionaryDriver.java This is a sample driver program you may use to test your LatinDictionary class.
Here are links to the three Java files and the Latin.txt datafile:
- DictionaryReader.java
- DictionaryEntry.java
- DictionaryDriver.java
- DictionaryADT.java
- Latin.txt
You do not have to open or parse the Latin.txt file. Use the DictionaryReader method getDictionaryArray(filename) to load the latin words and definitions into an array for the load(filename) in your LatinDictionary class.
To get an array of DictionaryEntry containing all the words in the dictionary:
1 | DictionaryEntry [] entries = DictionaryReader.getDictionaryArray(fileName); |
The DictionaryADT
As with previous assignments, all data structures must be in package data_structures. The DictionaryADT is an interface defined as follows:
1 | package data_structures; |
The DictionaryADT must be implemented in four ways:
- Binary Search Tree
- HashTable with chaining
- Ordered Array
- Red/Black Tree
For the first three implementations, you must write your own code. For the fourth implementation, the RedBlackTree, you will use the Java API class java.util.TreeMap, which is an implementation using a Red/Black tree. For the fourth implementation only, you may use any class in the Java API.
In your LatinDictionary class, you will instantiate an instance of DictionaryADT and hardcode your HashTable class:
1 | DictionaryADT<String,String> dictionary; |
Although you are hardcoding the HashTable in your LatinDictionary class, all four implementations should work identically with the application. Your DictionaryADT and your implementations must be in a package named data_structures.
Project Files
Your project will consist of the following files. You must use exactly these filenames.
- LatinDictionary.java The application program.
- Latin.txt The datafile, a text file containing Latin words and their definitions. The words do not occur in sorted order in the datafile. (provided)
- DictionaryReader.java Helper class to read the datafile. (provided)
- DictionaryEntry.java Helper class, a wrapper class to provide a single array that has both keys and values. (provided)
- DictionaryADT.java The dictionary interface. (provided)
- BinarySearchTree.java The binary search tree implementation of the DictionaryADT.
- HashTable.java The hash table implementation of the DictionaryADT. You must using chaining.
- UnorderedList.java A standard unordered linked list used for your hash table implementation. (Use your list class from project #2).
- OrderedArrayDictionary.java An ordered array implementations of the DictionaryADT.
- RedBlackTree.java The red/black tree implementation of the DictionaryADT. Use the Java TreeMap class.
The files DictionaryADT.java, BinarySearchTree.java, HashTable.java, UnorderedList.java, OrderedArrayDictionary.java, and RedBlackTree.java must be in a package named data_structures.
Project Submission
As with the previous assignments, you must place all of the files for your project that were not supplied in your handin/prog3 subdirectory. Please remember that the names of your files must match the specifications here.
Do not make a data_structures folder in your handin subdirectory.
IMPORTANT: As the due date falls at the end of the semester, there will be no opportunity for resubmission of your project. Please be certain that you have created and submitted your files correctly. If you have questions, please seek help from me.
Submit printed copy of your report only. Do NOT submit printouts of your Java source code files.