MCPcopy
hub / github.com/keon/algorithms / peek

Method peek

algorithms/data_structures/queue.py:112–123  ·  view source on GitHub ↗

Return the front element without removing it. Returns: The front element. Raises: IndexError: If the queue is empty.

(self)

Source from the content-addressed store, hash-verified

110 return value
111
112 def peek(self) -> object:
113 """Return the front element without removing it.
114
115 Returns:
116 The front element.
117
118 Raises:
119 IndexError: If the queue is empty.
120 """
121 if self.is_empty():
122 raise IndexError("Queue is empty")
123 return self._array[self._front]
124
125 def _expand(self) -> None:
126 """Double the size of the underlying array."""

Callers 1

test_array_queueMethod · 0.95

Calls 1

is_emptyMethod · 0.45

Tested by 1

test_array_queueMethod · 0.76