Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MyQueue(object):
- def __init__(self):
- self.old_to_new = []
- self.new_to_old = []
- def peek(self):
- if not self.new_to_old:
- while self.old_to_new:
- self.new_to_old.append(self.old_to_new.pop())
- val = self.new_to_old.pop()
- self.new_to_old.append(val)
- return val
- def pop(self):
- if not self.new_to_old:
- while self.old_to_new:
- self.new_to_old.append(self.old_to_new.pop())
- return self.new_to_old.pop()
- def put(self, value):
- self.old_to_new.append(value)
- queue = MyQueue()
- t = int(raw_input())
- for line in xrange(t):
- values = map(int, raw_input().split())
- if values[0] == 1:
- queue.put(values[1])
- elif values[0] == 2:
- queue.pop()
- else:
- print queue.peek()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement