Question
Hello, The code below is a method to add or put a new key value into a Java hash table. I need to add the
Hello, The code below is a method to add or "put" a new key value into a Java hash table. I need to add the count variable into this method that will increment when a collision occurs. Can you please show me where to add the "count" variable in the "put" method in order to do so?
Thank you!
//Initialize count variable:
private int count;
// insert the key-value pair into the symbol table
public void put(K key, V val) {
if (val == null) delete(key);
// double table size if 50% full
if (N >= M/2) resize(2*M);
int i;
for (i = hash(key); keys[i] != null; i = (i + 1) % M) {
if (keys[i].equals(key)) { vals[i] = val; return; }
}
keys[i] = key;
vals[i] = val;
N++;
}
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