当我将一个节点添加到双向链表时,我正面临内存泄漏。 我的职责是:
void addLast(const char* word){ // This is a homework and the parameter must be const char*
std::string c2 = word; // My nodes are std::string
Node *aux = new Node(c2);
if (tail == NULL) {
head = tail = aux; }
else {
tail->next = aux; aux->prev = tail; tail = aux; }
}
我的strct节点如下:
struct Node {
std::string value; Node *next, *prev;
Node (std::string value) {
this->value = value; next = prev = NULL; }
Node () {
next = prev = NULL; } }
我提到的事实是,如果我尝试删除函数addLast中的aux,我面临一个SEG FAULT。有什么问题>