Back to Library
QID: #24216
Solution for QID #24216: How could I implement these methods for a hash table? | StudyHelpMe
How could I implement these methods for a hash table?
boolean contains(DataT item) Returns the if item exists in the hash table.
void remove(DataT item) Returns the key from the hash table. If the item does not exist, then a NoSuchElement exception is thrown.
void rehash() Increases the capacity of and internally reorganizes the hash table to accommodate and access its entries more efficiently. This method is meant to be called automatically when the number of keys in the hash table exceeds this hash table's capacity and load factor.
Method given:
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
public class MyHashTable<DataType> {
private int numBuckets = 10;
private ArrayList<DataType>[] buckets;
private int count = 0;
public MyHashTable() {
buckets = new ArrayList[numBuckets];
for (int i = 0; i < numBuckets; i++) {
buckets[i] = new ArrayList<DataType>();
}
}
ZERO AI
Human Written
Human Written
PHD EXPERTS
Verified
Verified
TURNITIN
Clean Report
Clean Report
FAST DELIVERY
Instant/Hourly
Instant/Hourly