Queue

     Queue implementation Using Python              


from collections import deque
class Queue:
    def __init__(self):
        self.queue = deque()
    def enque(self,data):
        self.queue.append(data)

    def deque(self):
        return self.queue.popleft()

    def peek(self):

        return self.queue[0]
queueob = Queue()
t = int(input())
for i in range(t):
    operation = [int(i) for i in input().split()]
    if len(operation) == 2:
        queueob.enque(operation[1])
    elif operation[0] == 2:
        queueob.deque()
    elif operation[0] == 3:
        print(queueob.peek())
    print(queueob.queue)
Get Code Here

Post a Comment

0 Comments