forked from Py-Contributors/AlgorithmsAndDataStructure
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.py
More file actions
53 lines (45 loc) 路 1.06 KB
/
Copy pathstack.py
File metadata and controls
53 lines (45 loc) 路 1.06 KB
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
class Stack:
def __init__(self):
self.items = []
def isEmpty(self):
if self.items == []:
return True
else:
return False
def push(self, item):
self.items.append(item)
def pop(self):
if len(self.items) != 0:
return self.items.pop()
else:
print("Stack is empty")
def peek(self):
if len(self.items) != 0:
return self.items[len(self.items) - 1]
else:
print("Stack is empty")
def display(self):
return (self.items)
# __main__
s = Stack()
c = 0
while c != 5:
print('\tSTACK OPERATIONS')
print('1.Push')
print('2.Pop')
print('3.Peek')
print('4.Display Stack')
print('5.Exit')
c = int(input('Enter your choice(1-5): '))
if c == 1:
x = input("Enter the item: ")
s.push(x)
elif c == 2:
s.pop()
elif c == 3:
s.peek()
elif c == 4:
print(s.display())
elif c != 5:
print('Wrong Choice! Choose from 1 to 5 only')
print('Bye')