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--