我正在尝试用尾巴和头部实现双重衬里列表。
您能告诉我我犯错了吗
GitHub上的所有代码在这里: https://github.com/ZSzymon/Circual-Double-Linked-List
我认为问题是析构函数
ListV2::~ListV2()
{
Node *current = head;
Node *nextNode;
while(current->next)
{
nextNode = current->next;
delete current;
current = nextNode;
}
}
根据您的建议,我将析构函数更改为:
ListV2::~ListV2()
{
Node *nextNode;
while(head)
{
nextNode = head;
head = head->next;
delete nextNode;
}
}
尝试了一些调试。得到这个错误 “下等人停止了,因为它触发了异常。 在以下位置的线程0中停止:异常在0x9a3848,代码:0xc0000005:读取访问冲突在:0xfffffffffeeefef2,标志= 0x0(第一次机会)。“
这是Node结构
struct Node
{
std::string data;
Node *next;
Node *prev;
Node(std::string data):data(data)
{
next=nullptr;
prev=nullptr;
}
};
删除myList时程序崩溃了;