Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DATABASE Administrator Make A Difference

Authors: Mohciine Elmourabit

1st Edition

B0CGM7XG75, 978-1722657802

More Books

Students also viewed these Databases questions

Question

Question Can life insurance be used in a Keogh (HR 10) plan?

Answered: 1 week ago