-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue using list.py
More file actions
39 lines (38 loc) · 864 Bytes
/
queue using list.py
File metadata and controls
39 lines (38 loc) · 864 Bytes
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
num = int(input("enter the size of the queue\n"))
l=[]
input = []
while(True):
input = input("enter the command and required parameter\n").split(" ")
str = str(input[0])
n1 = int(input[1])
n2 = int(input[2])
if (len(l)>num):
break
if a=="insert":
l.insert(n1,n2)
elif a=="print":
print(l)
elif(a=="remove"):
l.remove(n1)
elif(a=="append"):
l.append(n1)
elif(a=="sort"):
l.sort()
elif(a=="pop"):
l.pop()
elif(a=="reverse"):
l.reverse()
else:
break
'''alternate code using eval functions'''
n = int(input())
l = []
for i in range(n):
s = input().split()
cmd = s[0]
args = s[1:]
if cmd !="print":
cmd += "("+ ",".join(args) +")"
eval("l."+cmd)
else:
print(l)