連鎖コードを使用したハッシュは次のとおりです。ここでいくつかのポインターの疑問があります
struct hash* hashTable = NULL;
int eleCount = 0;
struct node
{
int key;
int age;
char name[100];
struct node* next;
};
struct hash
{
struct node* head;
int count;
};
struct node* createNode(int key, char *name, int age)
{
struct node* newnode;
newnode = (struct node *)malloc(sizeof(struct node));
newnode->key = key;
newnode->age = age;
strcpy(newnode->name, name);
newnode->next = NULL;
return newnode;
}
void insertToHash(int key, char *name, int age)
{
int hashIndex = key % eleCount;
struct node* newnode = createNode(key, name, age);
/* head of list for the bucket with index "hashIndex" */
if (!hashTable[hashIndex].head)
{
hashTable[hashIndex].head = newnode;
hashTable[hashIndex].count = 1;
return;
}
/* adding new node to the list */
newnode->next = (hashTable[hashIndex].head);
/*
* update the head of the list and no of
* nodes in the current bucket
*/
hashTable[hashIndex].head = newnode;
hashTable[hashIndex].count++;
return;
}
ハッシュへのポインタだった配列がどのようにhashTable
変わったのでしょうか?? で、実際のところは
struct hash
{
struct node* head;
int count;
};
この構造が実際にどのように機能しているかわかりませんか?? 構造体へのポインタを配列として変換できますか???