From 787e0e30f9c63e9e54446cf7b6c5924e71992288 Mon Sep 17 00:00:00 2001 From: xiaok29 <1526783667@qq.com> Date: Thu, 16 May 2024 10:40:16 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20fix:=20=E5=8F=8C=E5=90=91?= =?UTF-8?q?=E9=98=9F=E5=88=97=E4=B8=BA=E7=A9=BA=E6=97=B6,pop=E4=B8=8D?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E6=8C=87=E5=90=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- codes/go/chapter_stack_and_queue/array_deque.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/codes/go/chapter_stack_and_queue/array_deque.go b/codes/go/chapter_stack_and_queue/array_deque.go index 85d98aca5..37b436f2b 100644 --- a/codes/go/chapter_stack_and_queue/array_deque.go +++ b/codes/go/chapter_stack_and_queue/array_deque.go @@ -72,6 +72,9 @@ func (q *arrayDeque) pushLast(num int) { /* 队首出队 */ func (q *arrayDeque) popFirst() any { num := q.peekFirst() + if num == nil { + return nil + } // 队首指针向后移动一位 q.front = q.index(q.front + 1) q.queSize-- @@ -81,6 +84,9 @@ func (q *arrayDeque) popFirst() any { /* 队尾出队 */ func (q *arrayDeque) popLast() any { num := q.peekLast() + if num == nil { + return nil + } q.queSize-- return num }