typedef struct hashnode
{
int data;
struct hashnode * next;
} hashnode;
struct hashnode hashtable[499]; //建立一个结构体数组
struct hashnode* p= &hashtable[M]; //进入循环 <====问题在这里,指针地址需要初始化为NULL吗?
while(p->next!=NULL) //循环遍历M处的链,直到指针为空 <===还有这里
{
if(p->data==nums[i])
{
return true; //如果与链上的数相等返回true
}
p = p->next;
}
一直显示这个:
Line 36: Char 24: runtime error: member access within misaligned address 0x00000000b77a for type 'struct hashnode', which requires 8 byte alignment [solution.c]
0x00000000b77a: note: pointer points here
struct hashnode* p= hashtable;就好了啊
搞这么复杂干啥
while(p->next!=NULL) //循环遍历M处的链,直到指针为空
这里是有问题的,p->next你并没有默认为NULL,可以在数据结构定义的时候增加构造函数来解决
typedef struct hashnode
{
int data;
struct hashnode * next;
hashnode() {data = 0;next = NULL;}
}hashnode;
大神解答一下!
呼唤大佬!
您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!