Files
zogo/examples/queue/main.go
T
4566704 80eb62cb08 feat(queue): 自 go-hua/queue 原样迁入链式队列
- 代码与测试不变,附 examples/queue 例程与包 README(含哨兵头结点 Pop 语义说明)
2026-09-20 12:20:51 +08:00

30 lines
710 B
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// queue 包示例:链式队列(Create 批量建队、Push 入列、Pop 出队、Print、Length)
package main
import (
"fmt"
"git.zeroonesoft.cn/golib/zogo/queue"
)
func main() {
// 头结点作为哨兵,Create 批量创建队列元素
q := &queue.QueueNode{}
q.Create(1, 2, 3)
fmt.Print("Create 后队列: ")
q.Print()
fmt.Println("Length:", q.Length())
// Push 入列(追加到队尾)
q.Push(4)
fmt.Print("Push 4 后: ")
q.Print()
fmt.Println("Length:", q.Length())
// Pop 出队:在头结点上调用,返回头结点自身 Data(哨兵为 nil),并使队列前进一个节点
_ = q.Pop()
fmt.Print("Pop 后队列: ")
q.Print()
fmt.Println("Length:", q.Length())
}