无法从连接到hashtable的列表中删除元素
我有一个实现链接冲突的哈希表。我有这个函数 void Elimina
,它应该用于从列表中消除一个元素,但该函数不会消除第一个元素。对于其他元素,效果很好。我该如何解决?
void elimina() {
int chiave, a;
printf("\nQuale elemento vuoi elimiare?\n");
scanf("%d", &chiave);
a = chiave % DIM_TABELLA;
c = head[a];
struct nodo *newnodo = (struct nodo *)malloc(sizeof(struct nodo));
newnodo->next = c;
if (head[a] == NULL)
printf("\nL'elemento non esiste");
else {
if (c->next->info == chiave) {
c = c->next;
free(c);
} else
if (c->next != NULL) {
while (c->info != chiave) {
b = c;
c = c->next;
}
}
if (c) {
b->next = c->next;
free(c);
}
}
}
I have a hashtable that implement chaining collision. I have this function void elimina
that should be used to eliminate an element from a list but the function doesn't eliminate the first element. For the other elements it works fine. How can I solve it?
void elimina() {
int chiave, a;
printf("\nQuale elemento vuoi elimiare?\n");
scanf("%d", &chiave);
a = chiave % DIM_TABELLA;
c = head[a];
struct nodo *newnodo = (struct nodo *)malloc(sizeof(struct nodo));
newnodo->next = c;
if (head[a] == NULL)
printf("\nL'elemento non esiste");
else {
if (c->next->info == chiave) {
c = c->next;
free(c);
} else
if (c->next != NULL) {
while (c->info != chiave) {
b = c;
c = c->next;
}
}
if (c) {
b->next = c->next;
free(c);
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
多个问题:
c
之前,您不会链接下一个节点,%
操作始终返回正数。这是一个修改版本:
Multiple problems:
c
%
operation always returns a positive number.Here is a modified version: