From 920556ace4fb0648bd01d5ad282ef89e493a5737 Mon Sep 17 00:00:00 2001 From: xiaok29 <1526783667@qq.com> Date: Tue, 14 May 2024 11:50:12 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20fix:=20=E9=98=9F=E5=88=97?= =?UTF-8?q?=E4=B8=BA=E7=A9=BA=E6=97=B6=E4=B8=8D=E5=BA=94=E8=AF=A5=E6=93=8D?= =?UTF-8?q?=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_queue.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/codes/go/chapter_stack_and_queue/array_queue.go b/codes/go/chapter_stack_and_queue/array_queue.go index 9068996a1..d8723e8e3 100644 --- a/codes/go/chapter_stack_and_queue/array_queue.go +++ b/codes/go/chapter_stack_and_queue/array_queue.go @@ -49,6 +49,10 @@ func (q *arrayQueue) push(num int) { /* 出队 */ func (q *arrayQueue) pop() any { num := q.peek() + if num == nil { + return nil + } + // 队首指针向后移动一位,若越过尾部,则返回到数组头部 q.front = (q.front + 1) % q.queCapacity q.queSize--