mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-12-18 09:10:16 +00:00
24 lines
435 B
Python
24 lines
435 B
Python
|
class Stack:
|
||
|
|
||
|
def __init__(self):
|
||
|
self.stack = []
|
||
|
self.top = 0
|
||
|
|
||
|
def is_empty(self):
|
||
|
return (self.top == 0)
|
||
|
|
||
|
def push(self, item):
|
||
|
if self.top < len(self.stack):
|
||
|
self.stack[self.top] = item
|
||
|
else:
|
||
|
self.stack.append(item)
|
||
|
|
||
|
self.top += 1
|
||
|
|
||
|
def pop(self):
|
||
|
if self.is_empty():
|
||
|
return None
|
||
|
else:
|
||
|
self.top -= 1
|
||
|
return self.stack[self.top]
|