algorithms-go/DataStructure/queue/list_queue.go
2021-04-07 18:13:02 +08:00

30 lines
425 B
Go

package queue
import "container/list"
//使用go标准库的list实现
type ListQueue struct {
l *list.List
}
func NewListQueue() *ListQueue {
l := list.New()
return &ListQueue{l}
}
func (lq *ListQueue) Shift() (el interface{}) {
e := lq.l.Front()
el = e.Value
lq.l.Remove(e)
return
}
func (lq *ListQueue) Push(el interface{}) {
lq.l.PushBack(el)
return
}
func (lq *ListQueue) Len() int {
return lq.l.Len()
}