A
priority queue is an abstract data structure that provides the following
operations:
You can add elements to it.
We can test if it is empty.
You can get the smallest element in the heap.
You can remove the smallest element in the heap.
The operations are not hard to implement. Here is a version that uses Python’s
list class
:
class PriorityQueue(object):
def __init__(self, seq = ()):
self.list = list(seq)
def is_empty(self):
return len(self.list) == 0
def __bool__(self):
return not ...