Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
3,834
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.89 KB | None | 0 0
  1. class MyQueue(object):
  2.     def __init__(self):
  3.         self.old_to_new = []
  4.         self.new_to_old = []
  5.    
  6.     def peek(self):
  7.         if not self.new_to_old:
  8.             while self.old_to_new:
  9.                 self.new_to_old.append(self.old_to_new.pop())
  10.         val = self.new_to_old.pop()
  11.         self.new_to_old.append(val)
  12.         return val
  13.        
  14.     def pop(self):
  15.         if not self.new_to_old:
  16.             while self.old_to_new:
  17.                 self.new_to_old.append(self.old_to_new.pop())
  18.         return self.new_to_old.pop()
  19.        
  20.     def put(self, value):
  21.         self.old_to_new.append(value)
  22.  
  23. queue = MyQueue()
  24. t = int(raw_input())
  25. for line in xrange(t):
  26.     values = map(int, raw_input().split())
  27.    
  28.     if values[0] == 1:
  29.         queue.put(values[1])        
  30.     elif values[0] == 2:
  31.         queue.pop()
  32.     else:
  33.         print queue.peek()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement