抱歉,我不想被指控再次作弊lol
答案 0 :(得分:2)
您的析构函数代码正在删除错误的节点。改为:
while (temp != NULL)
{
QueueNodePtr next = temp->link;
delete temp;
temp = next;
}
答案 1 :(得分:1)
您的Queue
析构函数未正确循环遍历节点。
在第一次循环迭代中,您使temp
跳过第一个节点并指向第二个节点,然后您delete
第二个节点并且不更新temp
,所以temp
现在指向第二次循环迭代中的无效节点。
请改为尝试:
Queue::~Queue()
{
//create new pointer and point it to front of list
QueueNodePtr temp = front;
//while list is not empty
while (temp != NULL)
{
//point to next node and delete the current node
QueueNodePtr next = temp->link;
delete temp;
temp = next;
}
}
或者这个:
Queue::~Queue()
{
//create new pointer and point it to front of list
QueueNodePtr temp = front;
//while list is not empty
while (temp != NULL)
{
//point to next node and delete the current node
QueueNodePtr curr = temp;
temp = temp->link;
delete curr;
}
}