【发布时间】:2015-11-08 03:46:28
【问题描述】:
如果afterWhat是head中包含的数字,以下是我在链表中插入数字的代码。 错误出现在代码的最后一行
head -> next = &temp;
错误是:
无法在赋值中将 Node** 转换为 Node*。
我想要做的是将 temp 的地址提供给 head.next,以便 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;? -
temp已经是指向节点的指针。你不想要head->next = temp;吗?
标签: c++ linked-list