-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue.go
More file actions
69 lines (59 loc) · 1.03 KB
/
Copy pathqueue.go
File metadata and controls
69 lines (59 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package queue
import (
"container/list"
)
type Queue struct {
v interface{}
list *list.List
}
func Create() *Queue {
return &Queue{
v : "",
list : list.New(),
}
}
func (q Queue) RPush(v string) {
q.list.PushBack(v)
}
func (q Queue) LPush(v string) {
q.list.PushFront(v)
}
func (q Queue) LPop() interface{} {
if q.list.Len() == 0 {
return ""
}
ele := q.list.Front()
q.v = q.list.Remove(ele)
return q.v
}
func (q Queue) RPop() interface{} {
if q.list.Len() == 0 {
return ""
}
ele := q.list.Back()
q.v = q.list.Remove(ele)
return q.v
}
func (q Queue) RemoveAll() {
q.list = list.New()
}
func (q Queue) Len() int {
return q.list.Len()
}
func (q Queue) LastVal() interface{} {
return q.v
}
/*
func main () {
q := Create()
fmt.Println(q.v)
q.RPush("demo")
q.RPush("s")
fmt.Println(q.Len())
fmt.Println(q.LPop())
fmt.Println(q.Len())
fmt.Println(q.LPop())
fmt.Println(q.Len())
fmt.Println(q.LPop())
}
*/