Python heaps and priority queues
A min-heap keeps the smallest item at index zero, but the rest of the backing list is not fully sorted. heappop restores the heap invariant after removing the minimum.
Python
import heapq
tasks = [(3, "backup"), (1, "alert"), (2, "email")]
heapq.heapify(tasks)
while tasks:
priority, name = heapq.heappop(tasks)
print(priority, name)
assert tasks == []