Skip to content

Commit

Permalink
modify Queue to use collections.deque instead of a list
Browse files Browse the repository at this point in the history
  • Loading branch information
the-shank committed Sep 26, 2016
1 parent ec4e068 commit 2f2cdf3
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lists/queue.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
from collections import deque


class Queue(object):
"""Wrapper around collections.deque to provide the api consistent with
a Queue"""

def __init__(self):
self.items = []
self.items = deque()

def __str__(self):
return ("Queue of size: %d" % len(self.items))
Expand All @@ -9,11 +15,10 @@ def isEmpty(self):
return len(self.items) == 0

def enqueue(self, item):
self.items.insert(0, item)
self.items.append(item)

def dequeue(self):
return self.items.pop()
return self.items.popleft()

def size(self):
return len(self.items)

0 comments on commit 2f2cdf3

Please sign in to comment.