Skip to content

Instantly share code, notes, and snippets.

@codeboy101
Created May 4, 2017 19:01
Show Gist options
  • Select an option

  • Save codeboy101/6236fdff67b9679cc7288dc87a64a8db to your computer and use it in GitHub Desktop.

Select an option

Save codeboy101/6236fdff67b9679cc7288dc87a64a8db to your computer and use it in GitHub Desktop.
class FIFOQueue(Queue):
"""A First-In-First-Out Queue."""
def __init__(self):
self.A = []
self.start = 0
def append(self, item):
self.A.append(item)
def __len__(self):
return len(self.A) - self.start
def extend(self, items):
self.A.extend(items)
def pop(self):
e = self.A[self.start]
self.start += 1
if self.start > 5 and self.start > len(self.A) / 2:
self.A = self.A[self.start:]
self.start = 0
return e
def __contains__(self, item):
return item in self.A[self.start:]
def __repr__(self):
return 'Frontier {}'.format(self.A)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment