One use of a hash table is to implement a set data type. You will implement the methods addElement, find, toString, resize, and the MySetIterator inner class in the class MySet. MySet uses a separate chaining hash table to implement a set of integers. To get started, import the starter file, MySet.java into the hashset package you create in a new Java Project. Please do not change any of the method signatures in either class. Implement the methods described below. You are free to test your code however you prefer. For additional programming practice, you can implement the union, intersect, difference methods (see the comments in the code for the desired functionality). private void resize() This method "doubles" the table size and reinserts the values stored in the current table. The table size should remain prime. private boolean find(Integer e) This method returns true if the integer e is in the set and false otherwise. private void addElement(Integer e) If e is not in the set, add e to the set, otherwise the set does not change. If after adding the new element numElements > 2*tableSize then call resize. This helps keep searching, inserting, and deleting into the set fast. private String toString() Returns a string representation for the set. The string representation of the set is { followed by a comma delimiter list of set elements followed by a }. The string for the empty set is {}. You should use the iterator you finish creating as described in the code. public class MySetIterator {...} Finish implementing the MySetIterator class to create an iterator for your set. This will allow you to iterate through your set when creating a String representation. See the comments in the code for more instructions. Below is method Signature class:
One use of a hash table is to implement a set data type. You will implement the methods addElement, find, toString, resize, and the MySetIterator inner class in the class MySet. MySet uses a separate chaining hash table to implement a set of integers. To get started, import the starter file, MySet.java into the hashset package you create in a new Java Project. Please do not change any of the method signatures in either class. Implement the methods described below. You are free to test your code however you prefer.
For additional programming practice, you can implement the union, intersect, difference methods (see the comments in the code for the desired functionality).
private void resize()
This method "doubles" the table size and reinserts the values stored in the current table. The table size should remain prime.
private boolean find(Integer e)
This method returns true if the integer e is in the set and false otherwise.
private void addElement(Integer e)
If e is not in the set, add e to the set, otherwise the set does not change. If after adding the new element numElements > 2*tableSize then call resize. This helps keep searching, inserting, and deleting into the set fast.
private String toString()
Returns a string representation for the set. The string representation of the set is { followed by a comma delimiter list of set elements followed by a }. The string for the empty set is {}. You should use the iterator you finish creating as described in the code.
public class MySetIterator {...}
Finish implementing the MySetIterator class to create an iterator for your set. This will allow you to iterate through your set when creating a String representation. See the comments in the code for more instructions.
Below is method Signature class:
Step by step
Solved in 3 steps