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

Method pop

algorithms/stack/ordered_stack.py:66–77  ·  view source on GitHub ↗

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

(self)

Source from the content-addressed store, hash-verified

64 self._push_direct(temp_stack.pop())
65
66 def pop(self) -> int:
67 """Remove and return the top element.
68
69 Returns:
70 The top (largest) element.
71
72 Raises:
73 IndexError: If the stack is empty.
74 """
75 if self.is_empty():
76 raise IndexError("Stack is empty")
77 return self.items.pop()
78
79 def peek(self) -> int:
80 """Return the top element without removing it.

Callers 15

test_ordered_stackMethod · 0.95
pushMethod · 0.95
is_palindrome_stackFunction · 0.45
is_sortedFunction · 0.45
first_switch_pairsFunction · 0.45
second_switch_pairsFunction · 0.45
first_stutterFunction · 0.45
second_stutterFunction · 0.45
is_validFunction · 0.45
remove_minFunction · 0.45
simplify_pathFunction · 0.45
first_is_consecutiveFunction · 0.45

Calls 1

is_emptyMethod · 0.95

Tested by 2

test_ordered_stackMethod · 0.76
_bfsFunction · 0.36