Created
October 2, 2018 08:34
-
-
Save BDeliers/8efa84e2bc022dffc91b206cb0862d8e to your computer and use it in GitHub Desktop.
Simple priority queue implementation for Python3
This file contains 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 PriorityQueue: | |
""" | |
Priority queue implementation | |
by BDeliers, June 2018 | |
""" | |
def __init__(self): | |
self.__queue = [] | |
def __repr__(self): | |
return self.__queue.__repr__() | |
def push(self, val): | |
i = 0 | |
while (i < len(self.__queue) and val <= self.__queue[i]): | |
i += 1 | |
self.__queue.insert(i, val) | |
def pop(self): | |
val = self.__queue[-1] | |
del self.__queue[-1] | |
return val | |
def empty(self): | |
return len(self.__queue) == 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment