From 84f4b8d285cf9e63c89404eb3c03d404ab2e85b7 Mon Sep 17 00:00:00 2001 From: Scai <71250849+Allen-Scai@users.noreply.github.com> Date: Thu, 25 Jan 2024 12:51:17 +0800 Subject: [PATCH] fix: Update linkedlist_deque.cpp (#1062) There is something error when delete node, should 'delete front' or 'delete rear' outside the body of if cycle. --- codes/cpp/chapter_stack_and_queue/linkedlist_deque.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/codes/cpp/chapter_stack_and_queue/linkedlist_deque.cpp b/codes/cpp/chapter_stack_and_queue/linkedlist_deque.cpp index d9cc953ed..35ec90ab8 100644 --- a/codes/cpp/chapter_stack_and_queue/linkedlist_deque.cpp +++ b/codes/cpp/chapter_stack_and_queue/linkedlist_deque.cpp @@ -92,8 +92,8 @@ class LinkedListDeque { if (fNext != nullptr) { fNext->prev = nullptr; front->next = nullptr; - delete front; } + delete front; front = fNext; // 更新头节点 // 队尾出队操作 } else { @@ -103,8 +103,8 @@ class LinkedListDeque { if (rPrev != nullptr) { rPrev->next = nullptr; rear->prev = nullptr; - delete rear; } + delete rear; rear = rPrev; // 更新尾节点 } queSize--; // 更新队列长度