Queues: A Tale of Two Stacks

  • + 1 comment

    Python:

    class MyQueue(object):
        # FIFO
        def __init__(self):
            self.queue = []
        
        def peek(self):
            return self.queue[0]
            
        def pop(self):
            if len(self.queue) != 0:
                return self.queue.pop(0)
            
        def put(self, value):
            self.queue.append(value)