44 lines
703 B
Go
44 lines
703 B
Go
package ds
|
|
|
|
type ListQueue[T any] struct {
|
|
list List[T]
|
|
}
|
|
|
|
var _ Queue[int] = &ListQueue[int]{}
|
|
|
|
func NewListQueue[T any](list List[T]) *ListQueue[T] {
|
|
return &ListQueue[T]{list}
|
|
}
|
|
|
|
func (s *ListQueue[T]) Enqueue(value T) {
|
|
s.list.Add(value)
|
|
}
|
|
|
|
func (s *ListQueue[T]) Add(value T) {
|
|
s.Enqueue(value)
|
|
}
|
|
|
|
func (s *ListQueue[T]) AddAll(values Iterable[T]) {
|
|
values.Each(s.Add)
|
|
}
|
|
|
|
func (s *ListQueue[T]) Dequeue() T {
|
|
return s.list.RemoveAt(0)
|
|
}
|
|
|
|
func (s *ListQueue[T]) Peek() T {
|
|
return s.PeekAt(0)
|
|
}
|
|
|
|
func (s *ListQueue[T]) PeekAt(index int) T {
|
|
return s.list.Get(index)
|
|
}
|
|
|
|
func (s *ListQueue[T]) Size() int {
|
|
return s.list.Size()
|
|
}
|
|
|
|
func (s *ListQueue[T]) Empty() bool {
|
|
return s.Size() == 0
|
|
}
|