Be concise.
Be useful.
All contributions dictatorially edited by webmasters to match personal tastes.
Please do not paste any copyright violating material.
Please try to avoid dependencies to third-party libraries and frameworks.
type Queue[T any] struct {
items []T
}
func (q *Queue[T]) Enqueue(t T) {
q.items = append(q.items, t)
}
func (q *Queue[T]) Dequeue() T {
t := q.items[0]
var zero T
q.items[0] = zero
q.items = q.items[1:]
return t
}
q := new(Queue[string])
q.Enqueue(x)
q.Enqueue(y)
z := q.Dequeue()
let q = [];
q.push(x);
q.push(y);
let z = q.shift();
q = Queue.new
q.enq(x)
q.enq(y)
z = q.deq