File tree Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change 1+ .. _go_algorithms :
2+
3+ Go 算法和数据结构
4+ =====================================================================
5+
6+ Queue
7+ --------------------------------------------------
8+
9+ .. code-block :: go
10+
11+ type Item struct {
12+ Num int
13+ Order int
14+ }
15+ type Queue struct {
16+ items []Item
17+ }
18+
19+ func NewQueue() *Queue {
20+ return &Queue{
21+ items: make([]Item, 0),
22+ }
23+ }
24+ func (q *Queue) Push(x Item) {
25+ q.items = append(q.items, x)
26+ }
27+
28+ func (q *Queue) Pop() Item {
29+ x := q.items[0]
30+ q.items = q.items[1:]
31+ return x
32+ }
33+
34+ func (q *Queue) Front() Item {
35+ return q.items[0]
36+ }
37+
38+ func (q *Queue) End() Item {
39+ return q.items[len(q.items)-1]
40+ }
41+
42+ func (q *Queue) Empty() bool {
43+ return len(q.items) == 0
44+ }
Original file line number Diff line number Diff line change @@ -9,3 +9,4 @@ Golang 快速入门 Go For Pythonisa
99
1010 web
1111 tricks
12+ algorithms
You can’t perform that action at this time.
0 commit comments