Created
May 4, 2017 19:01
-
-
Save codeboy101/6236fdff67b9679cc7288dc87a64a8db to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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