Files
2023-11-07 01:27:43 +02:00

24 lines
484 B
Python

from heapq import heappush, heappop
class Tasks:
def __init__(self):
self.heap = []
def add(self, name, priority):
heappush(self.heap, (-1 * priority, name))
def next(self):
return heappop(self.heap)[1]
if __name__ == "__main__":
t = Tasks()
t.add("siivous", 10)
t.add("ulkoilu", 50)
t.add("opiskelu", 50)
print(t.next()) # opiskelu
t.add("treffit", 100)
print(t.next()) # treffit
print(t.next()) # ulkoilu