Skip to content

Instantly share code, notes, and snippets.

@cristianrasch
Created March 31, 2012 16:48
Show Gist options
  • Save cristianrasch/2266670 to your computer and use it in GitHub Desktop.
Save cristianrasch/2266670 to your computer and use it in GitHub Desktop.
Python queue implementation
#!/usr/bin/env python
class Queue(object):
def __init__(self):
self.arr = []
def enqueue(self, val):
self.arr.insert(0, val)
def dequeue(self):
return self.arr.pop()
def __iter__(self):
return self
def next(self):
try:
return self.dequeue();
except IndexError:
raise StopIteration()
if __name__ == '__main__':
q = Queue()
for i in range(1, 11):
q.enqueue(i)
for e in q:
print 'Queued element: %d' % e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment