Week 7 Assignment 2 Deadline Tomorrow
unknown
python
2 years ago
603 B
5
Indexable
queue = []
while True:
op = input()
if op == "END":
break
if op.count('JOIN'):
value = op.split(',')[-1]
queue.append(int(value))
if op == "LEAVE":
queue.pop(0)
if op.count('HEAD'):
value = int(op.split(',')[-2])
idx = queue.index(value)
queue.insert(0, queue.pop(idx))
if op.count('TAIL'):
value = int(op.split(',')[-2])
idx = queue.index(value)
queue.append(queue.pop(idx))
if op == "PRINT":
print(','.join(str(item) for item in queue))Editor is loading...
Leave a Comment