mirror of
https://github.com/krahets/hello-algo.git
synced 2026-04-05 03:30:30 +08:00
fix(Go): Update array_queue.go and array_deque.go (#1362)
* 🐞 fix: 队列为空时不应该操作指向 * 🧪 test: 添加pop测试用例 * 🔧 build: 修改testify依赖包 * 🐞 fix: 双向队列为空时,pop不操作指向 * 🔧 build: Remove third-party packages * Delete codes/go/go.sum --------- Co-authored-by: Yudong Jin <krahets@163.com>
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user