Week 7 Assignment 2 Deadline Tomorrow

mail@pastecode.io avatar
unknown
python
a month ago
603 B
1
Indexable
Never
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