where can i find a good and clean example of hash table?
Thank you!
where can i find a good and clean example of hash table?
Thank you!
If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein
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.
Last edited by itsme86; 04-10-2006 at 11:12 AM.
If you understand what you're doing, you're not learning anything.