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

Method Peek

structure/circularqueue/circularqueuearray.go:84–91  ·  view source on GitHub ↗

Peek returns the item at the front of the queue without removing it. Returns an error if the queue is empty.

()

Source from the content-addressed store, hash-verified

82// Peek returns the item at the front of the queue without removing it.
83// Returns an error if the queue is empty.
84func (cq *CircularQueue[T]) Peek() (T, error) {
85 if cq.IsEmpty() {
86 var zeroValue T
87 return zeroValue, errors.New("queue is empty")
88 }
89
90 return cq.items[cq.front], nil
91}
92
93// Size returns the size of the queue.
94func (cq *CircularQueue[T]) Size() int {

Callers 2

TestCircularQueueFunction · 0.45
BenchmarkCircularQueueFunction · 0.45

Calls 1

IsEmptyMethod · 0.95

Tested by 2

TestCircularQueueFunction · 0.36
BenchmarkCircularQueueFunction · 0.36