30 lines
710 B
Go
30 lines
710 B
Go
// 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())
|
||
}
|