Question
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
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
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); } }
}
TestingAssignment2 *kkt Testing expanding the sixe of the Linear Probing Hash TablektkkStep 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