Created
October 7, 2015 03:10
-
-
Save gamesbrainiac/010ce42b15dba2576d06 to your computer and use it in GitHub Desktop.
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
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