Skip to content

Instantly share code, notes, and snippets.

@BDeliers
Created October 2, 2018 08:34
Show Gist options
  • Save BDeliers/8efa84e2bc022dffc91b206cb0862d8e to your computer and use it in GitHub Desktop.
Save BDeliers/8efa84e2bc022dffc91b206cb0862d8e to your computer and use it in GitHub Desktop.
Simple priority queue implementation for Python3
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