Other 2005 FR Questions | FR other years | Be Prepared Home |
The running times of the Part (b) We need to add a map where each key is a city and its // additional instance variable(s) private Map cityToCodeMap; // each key is a city, its // associated value is a set of postal codes // constructs an empty database public PostalCodeDB() { ... // initialization of additional instance variable(s) cityToCodeMap = new TreeMap(); }The following statements should be added to the addCityCodePair method(these statements are identical to the initial statements, but "code" and "city" are swapped everywhere): ... Set codeSet = getCodesForCity(city); if (codeSet == null) { codeSet = new HashSet(); cityToCodeMap.put(city, codeSet); } codeSet.add(code); Part (c) The running time of the Part (d) // prints an alphabetical list of all cities in this database // postcondition: the state of the data structure is not changed public void printAllCities() { Iterator it = cityToCodeMap.keySet().iterator(); while(it.hasNext()) System.out.println(it.next()); } 1Notes:
|
Copyright © 2005 by Skylight Publishing
support@skylit.com