-
Notifications
You must be signed in to change notification settings - Fork 8
/
stacks.py
32 lines (27 loc) · 661 Bytes
/
stacks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# Python implementation of stacks
# Create a Stack
def create_stack():
stack = []
return stack
# Check if the stack is empty
def IsEmpty(stack):
return len(stack) == 0
# PUSH operation
def PUSH(stack, value):
stack.append(value)
print('Pushed - ' + value)
# POP operation
def POP(stack):
if(IsEmpty(stack)):
return "Stack is empty"
return stack.pop()
# Driver code
stack = create_stack()
print("Empty Stack - " + str(stack))
PUSH(stack, str(1))
PUSH(stack, str(10))
PUSH(stack, str(100))
PUSH(stack, str(1000))
print("After PUSH - " + str(stack))
print("Popped - " + POP(stack))
print('Resultant Stack - ' + str(stack))