MCPcopy Index your code
hub / github.com/keon/algorithms / pop

Method pop

algorithms/data_structures/stack.py:96–109  ·  view source on GitHub ↗

Remove and return the top element. Returns: The top element. Raises: IndexError: If the stack is empty.

(self)

Source from the content-addressed store, hash-verified

94 self._array[self._top] = value
95
96 def pop(self) -> object:
97 """Remove and return the top element.
98
99 Returns:
100 The top element.
101
102 Raises:
103 IndexError: If the stack is empty.
104 """
105 if self.is_empty():
106 raise IndexError("Stack is empty")
107 value = self._array[self._top]
108 self._top -= 1
109 return value
110
111 def peek(self) -> object:
112 """Return the top element without removing it.

Callers 8

test_array_stackMethod · 0.95
_rotate_leftMethod · 0.45
_rotate_rightMethod · 0.45
_mergeMethod · 0.45
inorderMethod · 0.45
remove_minMethod · 0.45

Calls 1

is_emptyMethod · 0.45

Tested by 1

test_array_stackMethod · 0.76