how to convert this to java public HashTable *Rehash(int size,HashTable *htable)
ID: 3773760 • Letter: H
Question
how to convert this to java public HashTable *Rehash(int size,HashTable *htable) { //copy the existing content in a temporary table HashNode *table = htable->table; /* hashtable size doubled*/ htable->size = 2* size; htable->table = new HashNode [htable->size]; /*copy temporary table into double sized hash array */ for (int i = 0; i < htable->size; i++) { //getting position from find function int pos = Find(table[i].element, htable); htable->table[pos].element = key; } free(table); //return double sized hash table return htable; }Explanation / Answer
private void resize() {
//new hash with increased size
ListNode[] resizedTable = new ListNode[table.length*2];
//looing through each list value
for (int i = 0; i < table.length; i++) {
//getting each table row content
ListNode list = table[i];
while (list != null) {
//getting each row nodes
ListNode next = list.next;
//adding to them into appropriate position
int hash = (Math.abs(list.key.hashCode())) % resizedTable.length;
list.next = resizedTable[hash];
resizedTable[hash] = list;
list = next; // Move on to the next node in the OLD table.
}
}
//
table = resizedTable;
} // end resize()
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.