Week 7 Assignment 2 Deadline Tomorrow

 avatar
unknown
python
a year ago
603 B
2
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))
Leave a Comment