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