-
Notifications
You must be signed in to change notification settings - Fork 97
/
FIVE.py
42 lines (37 loc) · 956 Bytes
/
FIVE.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
class Node:
def __init__(self, data):
self.data = data
self.next = None
class Stack:
def __init__(self):
self.head = None
def push(self, data) -> None:
nn = Node(data)
nn.next = self.head
self.head = nn
def pop(self) -> None:
if(self.head!=None):
temp = self.head
self.head = temp.next
def status(self):
if(self.head != None):
temp = self.head
while temp.next!= None:
print(temp.data, end = "")
print("=>", end = "")
temp = temp.next
print(temp.data, end = "=>")
print("None")
# Do not change the following code
stack = Stack()
operations = []
for specific_operation in input().split(','):
operations.append(specific_operation.strip())
input_data = input()
data = input_data.split(',')
for i in range(len(operations)):
if operations[i] == "push":
stack.push(int(data[i]))
elif operations[i] == "pop":
stack.pop()
stack.status()