In the code:
import heapq
class PriorityQueue:
def __init__(self):
self._queue = []
self._index = 0
def push(self, item, priority):
heapq.heappush(self._queue, (-priority, self._index, item))
self._index += 1
class Person:
def __init__(self,name):
self.name = name
def __repr__(self):
return self.name
lista = PriorityQueue()
lista.push(Person('Dener'), 30)
lista.push(Person('Rodrigo'), 25)
lista.push(Person('Lucas'), 22)
I do not quite understand how the method works:
def push(self, item, priority):
heapq.heappush(self._queue, (-priority, self._index, item))
self._index += 1
Could anyone explain?