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

Method Dequeue

structure/circularqueue/circularqueuearray.go:57–70  ·  view source on GitHub ↗

Dequeue removes and returns the item from the front of the queue. Returns an error if the queue is empty.

()

Source from the content-addressed store, hash-verified

55// Dequeue removes and returns the item from the front of the queue.
56// Returns an error if the queue is empty.
57func (cq *CircularQueue[T]) Dequeue() (T, error) {
58 if cq.IsEmpty() {
59 var zeroValue T
60 return zeroValue, errors.New("queue is empty")
61 }
62 retVal := cq.items[cq.front]
63 if cq.front == cq.rear {
64 cq.front = -1
65 cq.rear = -1
66 } else {
67 cq.front = (cq.front + 1) % cq.size
68 }
69 return retVal, nil
70}
71
72// IsFull checks if the queue is full.
73func (cq *CircularQueue[T]) IsFull() bool {

Callers 2

TestCircularQueueFunction · 0.45
BenchmarkCircularQueueFunction · 0.45

Calls 1

IsEmptyMethod · 0.95

Tested by 2

TestCircularQueueFunction · 0.36
BenchmarkCircularQueueFunction · 0.36