MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / NewCircularQueue

Function NewCircularQueue

structure/circularqueue/circularqueuearray.go:29–39  ·  view source on GitHub ↗

NewCircularQueue creates a new CircularQueue with the given size. Returns an error if the size is less than or equal to 0.

(size int)

Source from the content-addressed store, hash-verified

27// NewCircularQueue creates a new CircularQueue with the given size.
28// Returns an error if the size is less than or equal to 0.
29func NewCircularQueue[T any](size int) (*CircularQueue[T], error) {
30 if size <= 0 {
31 return nil, errors.New("size must be greater than 0")
32 }
33 return &CircularQueue[T]{
34 items: make([]T, size),
35 front: -1,
36 rear: -1,
37 size: size,
38 }, nil
39}
40
41// Enqueue adds an item to the rear of the queue.
42// Returns an error if the queue is full.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected