26 lines
349 B
Go
26 lines
349 B
Go
|
package containers
|
||
|
|
||
|
type Queue[T any] struct {
|
||
|
items []T
|
||
|
}
|
||
|
|
||
|
func (q *Queue[T]) Push(item T) {
|
||
|
q.items = append(q.items, item)
|
||
|
}
|
||
|
|
||
|
func (q *Queue[T]) Pop() (T, bool) {
|
||
|
if len(q.items) == 0 {
|
||
|
var res T
|
||
|
return res, false
|
||
|
}
|
||
|
|
||
|
res := q.items[0]
|
||
|
q.items = q.items[1:]
|
||
|
|
||
|
return res, true
|
||
|
}
|
||
|
|
||
|
func NewQueue[T any]() *Queue[T] {
|
||
|
return &Queue[T]{}
|
||
|
}
|