Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started