Вот хеширование с кодом цепочки. Я имею некоторые сомнения указателей здесьхеширование с цепочкой c код
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;
};
Я не получаю, как эта структура на самом деле работает ?? Можно ли преобразовать любой указатель на структуру как массив ???
Очень сложно понять, о чем вы спрашиваете. Попробуйте уточнить. – nos
это хеш-таблица с цепочкой, это тот же вид структуры данных, что и список смежности в графах..ам не удается понять, как структура хеш-хэш-таблица используется в качестве массива внутри функции inserttohash –
Указатели и массивы ведут себя очень сходно в C. Вы можете использовать '[]' с обоими. – ugoren