Hi,
Does anyone know how to display contents of a hash table?
Thanks
Printable View
Hi,
Does anyone know how to display contents of a hash table?
Thanks
hi ,
i don't know exactly how you mean it ,
but maybe
struct nlist *lookup(char *s)
{
struct nlist *np;
for(np=hashtab[hash(s)]; np != NULL; np = np->next)
if (strcmp(s, np->name) == 0 )
return np; /*found*/
return NULL;/*not found*/
}
Now if I'm not mistaken (and if I remember correctly, as it has been a while since I've had to use hash tables), a hash table is nothing more than a souped up array.
So in order to display the contents you would basically treat it as if you are printing out the contents of an array (i.e. for an array w/10 spaces, print 0 - 9). You may hit some problems if your hash table had some collisions. If this is the case, it would depend on how you handled the collisions.
I'll look through my program to see if I can find any hash talbes...
Found the project I had to use a hash table in. Feel free to look at it. If you have any questions, feel free to ask and I'll see if I can remember enough to answer them. :D