I have been trying to fix a bug in a hash table and can't seem to figure out the issue.
I get to the point with a table that looks like this:
hash 0:
hash 1: tuft
hash 2: bale done
Next I try to add a word ("toga") but I get a segmentation fault. The code breaks when I call "delete[] table;" (line 13) after rehashing the items into the new table in the following code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
void rehashTable(unsignedint newCapacity) {
if (newCapacity == 0) {
clear();
}
else {
LinkedList<ItemType>* temp = new LinkedList<ItemType> [newCapacity];
unsignedint oldCapacity = capacity;
capacity = newCapacity;
for (int i = 0; i < oldCapacity; i++) {
for (int q = 0; q < table[i].getSize(); q++) { temp[hashItem(table[i].getItem(q))].insertItem(temp[hashItem(table[i].getItem(q))].getSize(), table[i].getItem(q));
}
}
delete[] table;
table = temp;
}
}
I've been working with this for a long time and can't figure it out. Any ideas? Thanks!