-
Notifications
You must be signed in to change notification settings - Fork 0
/
item-3.py
63 lines (52 loc) · 1.79 KB
/
item-3.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
60
61
62
63
class Queue :
def __init__(self, list = None):
if list == None :
self.items = []
else :
self.items = list
def isEmpty(self) :
return self.items == []
def enQueue(self, i) :
self.items.append(i)
def deQueue(self):
if not self.isEmpty() :
temp = self.items.pop(0)
print(temp[1])
else : print("Empty")
def size(self) :
return len(self.items)
def __str__(self) :
s = ""
if not self.isEmpty() :
for i in self.items :
s += i + " "
else :
s = "Empty"
return s
def addToMainQ(id) :
for i in range(len(member_list)) :
if member_list[i][1] == id :
if mainq.isEmpty() :
mainq.enQueue(member_list[i])
break
for j in range(mainq.size()) :
if member_list[i][0] == mainq.items[j][0] and j + 1 == mainq.size():
mainq.enQueue(member_list[i])
elif member_list[i][0] == mainq.items[j][0] and member_list[i][0] != mainq.items[j+1][0] and j + 1 != mainq.size():
mainq.items.insert(j+1, member_list[i])
break
elif member_list[i][0] != mainq.items[j][0] and j + 1 == mainq.size():
mainq.enQueue(member_list[i])
command = Queue()
mainq = Queue()
inp = input("Enter Input : ").split('/')
inp2 = [x for x in inp[0].split(',')]
member_list = []
for item in inp2 :
member_list.append(list(map(int, item.split())))
command.items = [x for x in inp[1].replace(',', ' ').split()]
for i in range(command.size()) :
if command.items[i] == 'D' :
mainq.deQueue()
elif command.items[i] == 'E' :
addToMainQ(int(command.items[i+1]))