Question: Create a version of the ChainHashMap that uses a linked positional list for each bucket. Note that the ChainHashMap implementation in Lab 8 used an
Create a version of the ChainHashMap that uses a linked positional list for each bucket.
Note that the ChainHashMap implementation in Lab used an UnsortedTableMap as a bucket, so the
implementation here would be different.
Implement the LinkedPositionalList class based on the class notes. The Iterable
PositionalList interface is provided.
Implement the Map interface using the interfaces and abstract classes from Part A Name your class
LinkedPositionalChainHashMap.
Use a linked positional list as the auxiliary data structure that holds entries of colliding keys.
You must use your own implementation of the LinkedPositionalList based on the
class notes.
Add a method named getCollisions that returns an integer representing the number
of collisions that occurred in your hashmap. Think of an efficient way to do this.
Modify the AbstractHashMap class so that the resize method uses an instance of your
LinkedPositionalList instead of an ArrayList. There should be no import of
ArrayList in any of your classes.
Create a class named PostalCode that stores:
Strings for the code, area, and province
double for latitude and longitude
include a natural ordering of postal codes in alphabetical order of the code
Create an OrderByLongitude comparator that orders postal codes from west to east. See here
for more information about longitude.
Create a class named QuickSort that uses the quicksort algorithm from class and a comparator
to sort elements of a collection stored as a queue or an array Overload your sorting algorithm to
work both with a default comparator and with a specified comparator. Make sure to reuse code.
In a PartBDriver class, create a hash map of Postal Codes.
read in the PartB.txt file
set each line as an instance of PostalCode
store each instance in your map, using the code stored in the first column of the given data
as the key and PostalCode instance as the value
In your output, display
The total number of postal codes
The number of collisions that occurred in the hashmap
An option for the user to sort by code or longitude
After displaying the output, include lines of code to do the following. You may use any of the postal
codes in the sample data for this.
Show the output of inserting an entry where the same key previously exists in the map.
Show the output of removing an entry where the key exists in the map.
Sample Output
Total Number of entries:
Number of collisions:
Display by code C or Longitude Lany other key to quit
display the value associated with each postal code or quit accordingly
Notes:
Your table array will hold a linked list of map entries eg declare
private LinkedPositionalList table;
Use the foreach loop, since elements are internal map entries you can make any updates
directly
Declare your hashmap as a LinkedPositionalChainHashMap in the driver ie not Map
and understand why this is necessary
Use the nextLine method of Scanner and split of String to parse the input data
The number of collisions should be ~ to ~ but may vary. Run several times to check. Think
about why the number of collisions may differ at each run.
The marker will be testing all methods, be sure to also test remove and put where an entry
with key k exists
You may choose to use either quickSort or quickSortInPlace
You will have to convert the Iterable of all values to a queue or an array iterate through and add
each element If you are using a queue, you must use the LinkedQueue implementation based
on the lecture notes. The Queue interface is provided.
Before our lecture on Sorting is comp, you can temporarily sort using Arrays.sort
Overload your sorting algorithm to work both with a default comparator and with a specified
comparator. Make sure to reuse code as necessary.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
