Problem :

https://www.hackerrank.com/challenges/ctci-queue-using-two-stacks/problem


My Solution :

#!/usr/bin/env python3


class Node(object):
    def __init__(self, data=None):
        self.data = data
        self.right = None


class MyQueue(object):
    def __init__(self):
        self.head = Node()
        self.tail = self.head

    def peek(self):
        if self.head.right:
            return self.head.right.data

    def pop(self):
        if self.head.right:
            data = self.head.right.data
            self.head = self.head.right
            self.head.data = None
            return data

    def put(self, value):
        self.tail.right = Node(value)
        self.tail = self.tail.right


queue = MyQueue()
t = int(input())
for line in range(t):
    values = map(int, input().split())
    values = list(values)
    if values[0] == 1:
        queue.put(values[1])
    elif values[0] == 2:
        queue.pop()
    else:
        print(queue.peek())