【发布时间】:2013-01-08 02:24:59
【问题描述】:
我创建了一个哈希表,我想从链表中删除一个节点。该代码适用于删除第一个节点,但不适用于删除其他节点。
void intHashTable::remove(int num){
int location = ((unsigned)num) % size;
Node * runner = table[location];
int checker;
if(runner->next == NULL){
if(num == table[location]->num){
table[location] = NULL;
}
}else{
if(table[location]->num == num){
table[location] = table[location]->next;
}else{
//This part doesn't seem to be working.
Node *temp = runner->next;
while(temp != NULL){
if(temp->num == num){
runner->next = temp->next;
delete(temp);
break;
}
}
}
}
}
【问题讨论】:
-
但是您已经尝试过什么?你发现了什么?在要求无偿支持时,请表现出一些努力。
-
@phresnel 我不要求无偿支持。我的代码在那里 - 这是我的努力。
-
那么,你已经尝试了什么?你发现了什么? “它不起作用”根本没有问题的努力。它不编译吗?它是否会因异常而崩溃?你有无限循环吗?你会内存不足吗?调试器说什么?仅举几个例子。
标签: c++ linked-list hashtable nodes