mirror of
https://github.com/krahets/hello-algo.git
synced 2024-12-24 10:26:27 +08:00
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.
This commit is contained in:
parent
c69ae9534d
commit
84f4b8d285
1 changed files with 2 additions and 2 deletions
|
@ -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--; // 更新队列长度
|
||||
|
|
Loading…
Reference in a new issue