這是我迄今爲止,但它不是在測試文件上工作。基本上跳到別的if(cnode == preposition)
如何刪除鏈接列表中的節點?
void LinkedList::Delete(Node *PrePosition) {
Node *cnode = head;
Node *pnode = NULL;
while (cnode != NULL) {
if (cnode->value != NULL) {
if (pnode == NULL) {
//if there is not previous node
head = cnode->next;
}
else if(cnode == PrePosition){
//if there is previous node
cout << endl << "Deleting: " << cnode << endl;
pnode->next = cnode->next;
}
}
else {
//dont delete
pnode = cnode;
}
cnode = cnode->next;
}
}
順便說一句,有關於geeksforgeeks.com的額外信息 – 2017-11-25 23:13:23
最好是將更多信息(包括鏈接)編輯到您的答案中,而不是將其添加爲評論 – PiedPiper
@PiedPiper,對不起,我對此很新穎,我請記住:) – 2017-11-26 21:10:02