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:
Scai 2024-01-25 12:51:17 +08:00 committed by GitHub
parent c69ae9534d
commit 84f4b8d285
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -92,8 +92,8 @@ class LinkedListDeque {
if (fNext != nullptr) { if (fNext != nullptr) {
fNext->prev = nullptr; fNext->prev = nullptr;
front->next = nullptr; front->next = nullptr;
delete front;
} }
delete front;
front = fNext; // 更新头节点 front = fNext; // 更新头节点
// 队尾出队操作 // 队尾出队操作
} else { } else {
@ -103,8 +103,8 @@ class LinkedListDeque {
if (rPrev != nullptr) { if (rPrev != nullptr) {
rPrev->next = nullptr; rPrev->next = nullptr;
rear->prev = nullptr; rear->prev = nullptr;
delete rear;
} }
delete rear;
rear = rPrev; // 更新尾节点 rear = rPrev; // 更新尾节点
} }
queSize--; // 更新队列长度 queSize--; // 更新队列长度