where can i find a good and clean example of hash table?
Thank you!
Printable View
where can i find a good and clean example of hash table?
Thank you!
how whould you recomend creating a hash table ia was thinking of something like this:
i have a struct
and i initialize hash a[100];Code:typedef struct hash
{
int inf;
struct *hash;
} hash;
i generate the hash key by doing smnthing like %100 and if it conflicts i create a simple linked list.
is this a good ideea? or there is someway better of aproaching it?
thank you!
You might want to consider a structure more like this:
And then create your table like this: struct hash *a[100];Code:struct hash
{
int inf;
struct hash *next;
};
That way you only have to deal with one struct which should simplify your code some.
That's the way I've seen it done and done it myself. Be aware that even if there are no conflicts (correct jargon: collisions) you'll still have a simple linked list at the array index that corresponds with your hash key. It will just contain one node (i.e. a[key]->next should equal NULL if there's no collisions and a[key] should equal NULL if that hash key never came up in your data set). Whatever data you're storing in your hash table will go into the struct's inf member.