You’ve been tasked with implementing a hashtable — this involves defining data types and functions to manipulate those types. I have no idea what you’re doing.
First define a hashtable — do this by defining two types; one table type and one slot type.
typedef struct table table;
typedef struct slot slot;
The table is a simple array of slots:
struct table {
slot slots[101];
}
The slot is a collection of data relevant to a defining string:
struct slot {
char status;
int hash;
char key[16];
};
A slot is either unused, deleted or in use depending on the value of status.
The hash of a slot is the value of the hash function on the key string.
The key string is stored in the key variable.
To store a string in the table, simply find an suitable slot and overwrite the data. To do this, search all the slots (using the algorithm described) untill you find an unused slot or one that already matches the key. If you can’t find either, look for a deleted slot and overwrite the slot.
To find a string, step through the table — if a slot matches the key return it, if you find an unused slot or finds a matching slot which has been deleted, stop the process. If you’ve looked at all the slots, stop as well.
To delete a string, first find it and then set the status to deleted.
solved hash it!! wrong answer, can’t figure out [closed]