Documentation ¶
Overview ¶
Package queue provides an implementation of a First In First Out (FIFO) queue. The FIFO queue is implemented using the doubly-linked list from the 'list' package.
Example ¶
q := New[int]() q.Enqueue(1) q.Enqueue(2) q.Each(func(i int) { fmt.Println(i) })
Output: 1 2
Example (Dequeue) ¶
q := New[int]() q.Enqueue(1) fmt.Println(q.Dequeue())
Output: 1
Example (Empty_empty) ¶
q := New[int]() fmt.Println(q.Empty())
Output: true
Example (Empty_nonempty) ¶
q := New[int]() q.Enqueue(1) fmt.Println(q.Empty())
Output: false
Example (Enqueue) ¶
q := New[int]() q.Enqueue(1)
Output:
Example (Peek) ¶
q := New[int]() q.Enqueue(1) fmt.Println(q.Peek())
Output: 1
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Queue ¶
type Queue[T any] struct { // contains filtered or unexported fields }
Queue is a simple First In First Out (FIFO) queue.
func (*Queue[T]) Dequeue ¶
func (q *Queue[T]) Dequeue() T
Dequeue removes and returns the item at the front of the queue.
A panic occurs if the queue is Empty.
func (*Queue[T]) Each ¶
func (q *Queue[T]) Each(fn func(t T))
Each calls 'fn' on every item in the queue, starting with the least recently pushed element.
Click to show internal directories.
Click to hide internal directories.