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

Method Enqueue

structure/circularqueue/circularqueuearray.go:43–53  ·  view source on GitHub ↗

Enqueue adds an item to the rear of the queue. Returns an error if the queue is full.

(item T)

Source from the content-addressed store, hash-verified

41// Enqueue adds an item to the rear of the queue.
42// Returns an error if the queue is full.
43func (cq *CircularQueue[T]) Enqueue(item T) error {
44 if cq.IsFull() {
45 return errors.New("queue is full")
46 }
47 if cq.IsEmpty() {
48 cq.front = 0
49 }
50 cq.rear = (cq.rear + 1) % cq.size
51 cq.items[cq.rear] = item
52 return nil
53}
54
55// Dequeue removes and returns the item from the front of the queue.
56// Returns an error if the queue is empty.

Callers 2

TestCircularQueueFunction · 0.45
BenchmarkCircularQueueFunction · 0.45

Calls 2

IsFullMethod · 0.95
IsEmptyMethod · 0.95

Tested by 2

TestCircularQueueFunction · 0.36
BenchmarkCircularQueueFunction · 0.36