我創建了一個哈希表,我想從鏈接列表中刪除一個節點。該代碼適用於刪除第一個節點,但不適用於刪除其他節點。刪除鏈接列表中的節點
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
那麼,你已經嘗試過什麼?你發現了什麼? 「它行不通」顯示沒有問題。它不會編譯?它是否會因異常而崩潰?你有無限循環嗎?你的內存不足嗎?調試器說什麼?僅舉幾個例子。 –