Question: In this question, you will write two ot the methods needed for vnainedHashet. public class ChainedHashSet implements Collection t private Entry 11Head; // The head

 In this question, you will write two ot the methods needed

In this question, you will write two ot the methods needed for vnainedHashet. public class ChainedHashSet implements Collection t private Entry 11Head; // The head node of each of the inked lists public class Entry next; private E element; public Entry(E elem) ( elementelem; A)[10 poinis] Because lots of objects can be hashed to the same index, many of Chainedfashser's method need to check if an element is already in a linked list. Implement exista so that it returns true if elan is already in the list at 11Head [index] and returns talse if olem is not in that list. Remember that some array entries could be for an empty list! public boolean exista (int index, E elem) t B) [12 points] Now write the add() method. To add an element, we start by getting the element's hash. Since this class is not a multiset, we need to retun false if we elem is already on the list. (You can use the method from part (a) for this, even if you did not complete that part). If eles was not on the list, add eles to the back of the list and return true. Remember that 11Head [index] might be empty! public boolean add (E elem) int index -hash (elem); // index is the index in 11Head to use In this question, you will write two ot the methods needed for vnainedHashet. public class ChainedHashSet implements Collection t private Entry 11Head; // The head node of each of the inked lists public class Entry next; private E element; public Entry(E elem) ( elementelem; A)[10 poinis] Because lots of objects can be hashed to the same index, many of Chainedfashser's method need to check if an element is already in a linked list. Implement exista so that it returns true if elan is already in the list at 11Head [index] and returns talse if olem is not in that list. Remember that some array entries could be for an empty list! public boolean exista (int index, E elem) t B) [12 points] Now write the add() method. To add an element, we start by getting the element's hash. Since this class is not a multiset, we need to retun false if we elem is already on the list. (You can use the method from part (a) for this, even if you did not complete that part). If eles was not on the list, add eles to the back of the list and return true. Remember that 11Head [index] might be empty! public boolean add (E elem) int index -hash (elem); // index is the index in 11Head to use

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!