我似乎无法弄清楚问题出在哪里,我的代码编译并运行了下面显示的有问题的函数,但是当我尝试显示所有节点的内容时,我得到了:
LinkedList.exe中0x50CE1F98(msvcp100d.dll)的未处理异常:0xC0000005:访问冲突读取位置0xFEEEFEEE。
//remove (and cleanup after) the node at the tail of the LinkedList (pHead)
//return a pointer to the head node
ListNode* removeEnd( ListNode* pHead )
{
ListNode* pCurr = pHead;
ListNode* pPrevPtr = NULL;
while (pCurr->pNextNode != NULL)
{
pCurr = pCurr->pNextNode;
pPrevPtr = pCurr->pNextNode;
}
pPrevPtr = NULL;
delete pCurr;
return pHead;
}
最佳答案
它一定要是:
while (pCurr->pNextNode != NULL)
{
pPrevPtr = pCurr;
pCurr = pCurr->pNextNode;
}
关于c++ - 在C++中删除链接列表的最后一个节点,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22366221/