File tree Expand file tree Collapse file tree 1 file changed +3
-3
lines changed Expand file tree Collapse file tree 1 file changed +3
-3
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,6 @@ class StackOverflowError(BaseException):
7
7
class StackUnderflowError (BaseException ):
8
8
pass
9
9
10
-
11
10
class Stack :
12
11
"""A stack is an abstract data type that serves as a collection of
13
12
elements with two principal operations: push() and pop(). push() adds an
@@ -35,8 +34,8 @@ def push(self, data):
35
34
36
35
def pop (self ):
37
36
"""Pop an element off of the top of the stack."""
38
- if len ( self .stack ) <= 0 :
39
- raise StackUnderflowError
37
+ if not self .stack : # Condition to check Underflow of stack
38
+ pass
40
39
return self .stack .pop ()
41
40
42
41
def peek (self ):
@@ -69,6 +68,7 @@ def test_stack() -> None:
69
68
assert stack .is_full () is False
70
69
assert str (stack ) == "[]"
71
70
71
+
72
72
try :
73
73
_ = stack .pop ()
74
74
assert False # This should not happen
You can’t perform that action at this time.
0 commit comments