0
以下是我的代碼,用於在鏈接列表中插入數字,如果在頭部包含的數字之後。 的錯誤出現在代碼的最後一行,其中指定節點的指針地址
頭 - >未來= &temp;
的錯誤是:
不能轉換節點**到節點*賦值。
我想要做的就是給head.next指定temp的地址,這樣head就會指向temp。
void LinkedList::insertAfter(int toInsert, int afterWhat)
{
if(head->data == afterWhat)
{
Node* temp = new Node;
temp->next = head->next;
temp->data = toInsert;
head->next = &temp;
}
}
'head-> next = temp;'? – Downvoter
'temp'已經是一個指向節點的指針。你不只是想'head-> next = temp;'? – Kevin