Skip to content

Instantly share code, notes, and snippets.

@gamesbrainiac
Created October 7, 2015 03:10
Show Gist options
  • Save gamesbrainiac/010ce42b15dba2576d06 to your computer and use it in GitHub Desktop.
Save gamesbrainiac/010ce42b15dba2576d06 to your computer and use it in GitHub Desktop.
import heapq
class PriorityQueue(object):
def __init__(self):
self._queue = []
self._index = 0
def push(self, item, priority):
heapq.heappush(self._queue, (-priority, self._index, item))
self._index += 1
def pop(self):
return heapq.heappop(self._queue)[-1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment