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

Method peek

algorithms/stack/ordered_stack.py:79–85  ·  view source on GitHub ↗

Return the top element without removing it. Returns: The top (largest) element.

(self)

Source from the content-addressed store, hash-verified

77 return self.items.pop()
78
79 def peek(self) -> int:
80 """Return the top element without removing it.
81
82 Returns:
83 The top (largest) element.
84 """
85 return self.items[len(self.items) - 1]
86
87 def size(self) -> int:
88 """Return the number of elements in the stack.

Callers 2

test_ordered_stackMethod · 0.95
pushMethod · 0.95

Calls

no outgoing calls

Tested by 1

test_ordered_stackMethod · 0.76