Skip to content

Instantly share code, notes, and snippets.

@radixdev
Created February 27, 2014 23:25
Show Gist options
  • Select an option

  • Save radixdev/9261894 to your computer and use it in GitHub Desktop.

Select an option

Save radixdev/9261894 to your computer and use it in GitHub Desktop.
coding for interviews #20
class Queue(object):
def __init__(self):
self.stack1 = Stack()
self.stack2 = Stack()
def enqueue(self,p):
self.stack1.push(p)
def dequeue(self):
#pop off all in 1 onto 2
while not self.stack1.isEmpty():
self.stack2.push(self.stack1.pop())
#pop off stack 1
returnValue = self.stack2.pop()
#re pop off all in 2 onto 1
while not self.stack2.isEmpty():
self.stack1.push(self.stack2.pop())
return returnValue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment