Documentation
¶
Overview ¶
Package queue provides an implementation of a circular queue data structure.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CircularQueue ¶
type CircularQueue[T any] struct { // contains filtered or unexported fields }
CircularQueue represents a circular queue data structure.
func NewCircularQueue ¶
func NewCircularQueue[T any](size int) (*CircularQueue[T], error)
NewCircularQueue creates a new CircularQueue with the given size. Returns an error if the size is less than or equal to 0.
func (*CircularQueue[T]) Dequeue ¶
func (cq *CircularQueue[T]) Dequeue() (T, error)
Dequeue removes and returns the item from the front of the queue. Returns an error if the queue is empty.
func (*CircularQueue[T]) Enqueue ¶
func (cq *CircularQueue[T]) Enqueue(item T) error
Enqueue adds an item to the rear of the queue. Returns an error if the queue is full.
func (*CircularQueue[T]) IsEmpty ¶
func (cq *CircularQueue[T]) IsEmpty() bool
IsEmpty checks if the queue is empty.
func (*CircularQueue[T]) IsFull ¶
func (cq *CircularQueue[T]) IsFull() bool
IsFull checks if the queue is full.
func (*CircularQueue[T]) Peek ¶
func (cq *CircularQueue[T]) Peek() (T, error)
Peek returns the item at the front of the queue without removing it. Returns an error if the queue is empty.
func (*CircularQueue[T]) Size ¶
func (cq *CircularQueue[T]) Size() int
Size returns the size of the queue.