我无法弄清楚如何打印出我存储在此哈希表中的值。
代码
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
typedef struct node
{
char word;
char* name;
struct node* next;
}
node;
node* first[26] = {NULL};
int main(char* name)
{
char* names[] = { "nick", "noah", "kyle", "sam", "hugo", "batman"};
int hashedValue = hash(name);
insert(hashedValue, name);
}
int hash(const char* buffer)
{
return tolower(buffer[0]) - 'a';
}
void insert(int key, const char* buffer)
{
// try to instantiate node to insert word
node* newptr = malloc(sizeof(node));
if (newptr == NULL)
{
return;
}
// make a new pointer
strcpy(newptr->word, buffer);
newptr->next = NULL;
// check for empty list
if (first[key] == NULL)
{
first[key] = newptr;
}
// check for insertion at tail
else
{
node* predptr = first[key];
while(1)
{
// insert at tail
if (predptr->next == NULL)
{
predptr->next = newptr;
break;
}
// update pointer
predptr = predptr->next;
}
}
}
问: 我想知道如何打印我存储在这个哈希表程序中的值。