因此,我正在尝试使用c ++中的精巧链接冲突方法实现Hashtable。请记住,由于我只是从C切换而来的,所以我还没有学习过类或对象或任何这些东西。无论如何,由于某种原因,我有一个指针数组应该传递给名为insert的函数。给了我一个错误,经过进一步研究,显然通过引用传递数组是非法的,所以我该如何解决。我似乎对数组也很困惑,数组是指针吗? arr [0]是否等于* p [0]?
#include<iostream>
#include<cstdlib>
struct node
{
int data;
node* next;
};
int HashGroup=8;
void Insert(node& HashList[], int key);
int HashFunction(int key);
int main()
{
node* HashTable[HashGroup];
for(int i=0;i<HashGroup;i++)
HashTable[i]=NULL;
Insert(HashTable,36);
Insert(HashTable,18);
}
int HashFunction(int key)
{
return key%8;
}
void Insert(node& HashList[], int key)
{
node* p=NULL;
node* t=new node;
t->data=key;
t->next=NULL;
int index=HashFunction(key);
if(HashList[index]==NULL)
HashList[index]=t;
else
{
p=HashList[index];
while(p->next)
p=p->next;
p->next=t;
}
}