Peek returns the item at the front of the queue without removing it. Returns an error if the queue is empty.
()
| 82 | // Peek returns the item at the front of the queue without removing it. |
| 83 | // Returns an error if the queue is empty. |
| 84 | func (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. |
| 94 | func (cq *CircularQueue[T]) Size() int { |