feat(queue): 自 go-hua/queue 原样迁入链式队列

- 代码与测试不变,附 examples/queue 例程与包 README(含哨兵头结点 Pop 语义说明)
This commit is contained in:
2026-09-20 12:20:51 +08:00
parent 75f0b78d52
commit 80eb62cb08
4 changed files with 198 additions and 0 deletions
+44
View File
@@ -0,0 +1,44 @@
package queue
import "testing"
func TestCreateAndLength(t *testing.T) {
q := &QueueNode{}
q.Create(1, 2, 3)
if got := q.Length(); got != 3 {
t.Errorf("Length = %d, want 3", got)
}
}
func TestPush(t *testing.T) {
q := &QueueNode{}
q.Create("a")
q.Push("b")
if got := q.Length(); got != 2 {
t.Errorf("Push 后 Length = %d, want 2", got)
}
}
func TestPop(t *testing.T) {
q := &QueueNode{}
q.Create(1, 2, 3)
// Pop 在头结点(哨兵)上调用,跳过第一个元素并返回头结点 Data
q.Pop()
if got := q.Length(); got != 2 {
t.Errorf("Pop 后 Length = %d, want 2", got)
}
}
func TestCreateEmpty(t *testing.T) {
q := &QueueNode{}
q.Create() // 无元素,不应 panic
if got := q.Length(); got != 0 {
t.Errorf("空 Create 后 Length = %d, want 0", got)
}
}
func TestPrint(t *testing.T) {
q := &QueueNode{}
q.Create(1, 2, 3)
q.Print() // 仅验证不 panic
}