Skip to content

Latest commit

 

History

History

challenge-40

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

Queue Using Two Stacks

This problem was asked by Apple.

Description

Implement a queue class using two stacks. A queue is a data structure that supports the FIFO protocol (First in = first out). Your class should support the enqueue and dequeue methods like a standard queue.

Example

class Queue:
  def __init__(self):
    # Fill this in.
    
  def enqueue(self, val):
    # Fill this in.

  def dequeue(self):
    # Fill this in.

q = Queue()

q.enqueue(1)
q.enqueue(2)
q.enqueue(3)

print q.dequeue() # 1
print q.dequeue() # 2
print q.dequeue() # 3