Push an element to the top of the stack. >>> S = Stack(2) # stack size = 2 >>> S.push(10) >>> S.push(20) >>> print(S) [10, 20] >>> S = Stack(1) # stack size = 1 >>> S.push(10) >>> S.push(20) Traceback (most recent cal
(self, data: T)
| 33 | return str(self.stack) |
| 34 | |
| 35 | def push(self, data: T) -> None: |
| 36 | """ |
| 37 | Push an element to the top of the stack. |
| 38 | |
| 39 | >>> S = Stack(2) # stack size = 2 |
| 40 | >>> S.push(10) |
| 41 | >>> S.push(20) |
| 42 | >>> print(S) |
| 43 | [10, 20] |
| 44 | |
| 45 | >>> S = Stack(1) # stack size = 1 |
| 46 | >>> S.push(10) |
| 47 | >>> S.push(20) |
| 48 | Traceback (most recent call last): |
| 49 | ... |
| 50 | data_structures.stacks.stack.StackOverflowError |
| 51 | |
| 52 | """ |
| 53 | if len(self.stack) >= self.limit: |
| 54 | raise StackOverflowError |
| 55 | self.stack.append(data) |
| 56 | |
| 57 | def pop(self) -> T: |
| 58 | """ |