feat(queue): 自 go-hua/queue 原样迁入链式队列
- 代码与测试不变,附 examples/queue 例程与包 README(含哨兵头结点 Pop 语义说明)
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
// 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())
|
||||
}
|
||||
Reference in New Issue
Block a user