How do I make a hash table representation using an array in C++ for a table and apply a hash function such as k % 10 to it? I’m to use chaining to resolve collision (i.e. the table is an array of linked lists).
I am to also insert, search, and delete values into/from this table.
So far, I have:
struct Node {
int value;
Node* next;
};
void insert(int n, Node* hashtable[]) {
int x = n % 10;
... ...
Say for example for the value 10, my hash function would produce 0, so 10 goes into the first slot of the array/hash table.
Then if I had the value 100, 100 would also go to the first slot, so my 10 would “point” to 100… how would I code this?
something like
This will add the most recent collision to the front of the linked list, i.e. it operates as a stack. Adding it to the back is left as an exercise for the questioner!