Skip to content

Instantly share code, notes, and snippets.

@cli248
Last active December 31, 2015 04:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cli248/7933690 to your computer and use it in GitHub Desktop.
Save cli248/7933690 to your computer and use it in GitHub Desktop.
Implement the Queue data structure using two Stacks
class Queue():
def __init__(self):
self.inbox = []
self.outbox = []
def enqueue(self, item):
self.inbox.append(item)
def dequeue(self):
if not self.outbox:
while self.inbox:
self.outbox.append(self.inbox.pop())
try:
return self.outbox.pop()
except IndexError:
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment