我创建了一个哈希表,我想从链接列表中删除一个节点。该代码适用于删除第一个节点,但不适用于删除其他节点。删除链接列表中的节点
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我不要求无偿支持。我的代码在那里 - 这是我的努力。 – user1965283
那么,你已经尝试过什么?你发现了什么? “它行不通”显示没有问题。它不会编译?它是否会因异常而崩溃?你有无限循环吗?你的内存不足吗?调试器说什么?仅举几个例子。 –