diff --git a/codes/cpp/chapter_stack_and_queue/linkedlist_deque.cpp b/codes/cpp/chapter_stack_and_queue/linkedlist_deque.cpp index 1bbccc48c..76a10cbd5 100644 --- a/codes/cpp/chapter_stack_and_queue/linkedlist_deque.cpp +++ b/codes/cpp/chapter_stack_and_queue/linkedlist_deque.cpp @@ -92,6 +92,7 @@ public: if (fNext != nullptr) { fNext->prev = nullptr; front->next = nullptr; + delete front; } front = fNext; // 更新头结点 // 队尾出队操作 @@ -102,6 +103,7 @@ public: if (rPrev != nullptr) { rPrev->next = nullptr; rear->prev = nullptr; + delete rear; } rear = rPrev; // 更新尾结点 }