Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with the expand method !!! public class LinearProbingHashTable { private Entry[] hashArray; private Entry defunct; public LinearProbingHashTable(int size) { hashArray = new

I need help with the expand method !!!

public class LinearProbingHashTable { private Entry[] hashArray; private Entry defunct;

public LinearProbingHashTable(int size) { hashArray = new Entry[size]; defunct = new Entry(-1, null); }

public int hashFunc(int key) { return key % hashArray.length; }

public boolean isFull() { for (int i = 0; i

public void displayTable() { for (int j = 0; j

public void insertOld(int k, E d) { if (!isFull()) { int hashVal = hashFunc(k); while (hashArray[hashVal] != null && hashArray[hashVal] != defunct) { ++hashVal; hashVal %= hashArray.length; } hashArray[hashVal] = new Entry(k, d); } }

public void insert(int k, E d) { if (isFull()){ expand(2*hashArray.length); }

int hashVal = hashFunc(k); while (hashArray[hashVal] != null && hashArray[hashVal] != defunct) { ++hashVal; hashVal %= hashArray.length; } hashArray[hashVal] = new Entry(k, d); }

public E find(int k) { int hashVal = hashFunc(k); int start = hashVal; boolean checkAll = false; while (hashArray[hashVal] != null && !checkAll) { if (hashArray[hashVal].key == k) return (E) hashArray[hashVal].data; ++hashVal; hashVal %= hashArray.length; if (hashVal == start) checkAll = true; } return null; }

public E delete(int k) { int hashVal = hashFunc(k); int start = hashVal; boolean checkAll = false; while (hashArray[hashVal] != null && !checkAll) { if (hashArray[hashVal].key == k) { E temp = (E) hashArray[hashVal].data; hashArray[hashVal] = defunct; return temp; } ++hashVal; hashVal %= hashArray.length; if (hashVal == start) checkAll = true; } return null; }

private void expand( int newCapacity ) { // Input code here !!! }

// INCLUDED FOR TESTING public int getCapacity() { return hashArray.length; }

public class Entry { private int key; private E data;

public Entry(int k, E d) { key = k; data = d; }

public int getKey() { return key; }

public E getData() { return data; } public void display() { System.out.print(key + ":"); System.out.println(data); } }

}

image text in transcribed

TestingAssignment2 *kkt Testing expanding the sixe of the Linear Probing Hash Tablektkk

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

Statistical And Scientific Database Management International Working Conference Ssdbm Rome Italy June 21 23 1988 Proceedings Lncs 339

Authors: Maurizio Rafanelli ,John C. Klensin ,Per Svensson

1st Edition

354050575X, 978-3540505754

More Books

Students also viewed these Databases questions