You have not updated temp to point to the next element of the loop:
temp = temp->next;
You also present an empty row with a NULL pointer in your table, but you do not handle this case correctly in your code - if runner is NULL , then you will break when you try to access runner->next in the first check. Also, in some cases, you cannot delete the node.
To fix these problems, you can update your code something like this:
void intHashTable::remove(int num) { int location = ((unsigned)num) % size; Node * runner = table[location]; if (runner != NULL) { if (runner->num == num) { delete runner; table[location] = NULL; } else { while (runner->next != NULL) { if (runner->next->num == num) { Node *temp = runner->next; runner->next = runner->next->next; delete temp; break; } runner = runner->next; } } } }
Also note that I removed the brackets from delete , which is a C ++ keyword, not a function.
If you use doubly linked lists (i.e. with the previous pointer, as well as the next), you can simplify this code a bit, although for something like a hash table where you only tend to scroll in one direction, it may not be worth the expense to an additional pointer (additional 8 bytes per element in a 64-bit system).
source share