-
Notifications
You must be signed in to change notification settings - Fork 828
/
stack.py
59 lines (46 loc) · 1.55 KB
/
stack.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
class Stack:
def __init__(self):
self.items = []
def push(self, item):
return self.items.append(item)
def pop(self):
if self.is_empty():
return print("Stack is Empty")
return self.items.pop()
def is_empty(self):
return self.items == []
def stack_length(self):
return len(self.items)
def peek(self):
if self.is_empty():
return print("Stack is Empty")
return self.items[-1]
def main():
stack = Stack()
print("Type Your Name : ")
name = input()
print("Welcome " + name)
print("Choose your option")
while True:
print(" 1. Push \n 2. Pop \n 3. Length \n 4. Top-Item \n 5. Show Stack")
print("________________________\n________________________")
choice = input()
if choice == "1":
print("Enter Element (Any Data Type)")
x = input()
stack.push(x)
print("*********************\n*********************")
elif choice == "2":
stack.pop()
elif choice == "3":
print('Length of the Stack is in Below')
print(stack.stack_length())
print("*********************\n*********************")
elif choice == "4":
print("Next Pop Item is in below")
print(stack.peek())
print("*********************\n*********************")
elif choice == "5":
print(stack.items)
print("*********************\n*********************")
main()