<分区>
我正在尝试使用链表数组实现单独的链接。首先我初始化了结构数组,它最终由 10 个头节点组成,最初什么都没有,不是 0,节点中什么也没有。
我认为这会起作用:
void Hash::sepChain(int key){
int i;
//initialize array with Null
myNode a[10];
for(i=0; i<10; i++){
a[i] = NULL;
}
myNode->item = key;
myNode->next = a[key%tableSize];
a[key%tableSize] = myNode;
}
但是我收到了这个错误。
hash.cpp:176:10: error: no viable overloaded '='
a[i] = NULL;
~~~~ ^ ~~~~
./hash.hpp:30:8: note: candidate function (the implicit copy assignment operator)
not viable: no known conversion from 'long' to 'const myNode' for 1st
argument
struct myNode{
^
这就是我在 .hpp 中编写结构的方式
struct myNode{
int item;// the value that goes into the node
myNode *next;
};
为什么会出现此错误,我该如何解决?谢谢。