zhukov000

Deque

Nov 8th, 2019
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. queue = []
  2.  
  3. while True:
  4. cmd = input()
  5. if cmd == "exit":
  6. print("bye")
  7. break
  8. elif cmd == 'pop_front':
  9. print( queue.pop(0) )
  10. elif cmd == 'pop_back':
  11. print( queue.pop() )
  12. elif cmd == 'front':
  13. print( queue[0] )
  14. elif cmd == 'back':
  15. print( queue[-1] )
  16. elif cmd == 'size':
  17. print( len(queue) )
  18. elif cmd == 'clear':
  19. queue.clear()
  20. print('ok')
  21. else:
  22. c, n = cmd.split()
  23. if c == 'push_back':
  24. queue.append(n)
  25. else:
  26. queue.insert(0, n)
  27. print('ok')
Advertisement
Add Comment
Please, Sign In to add comment