实现一个优先级队列-win32串口通信-serial communications in win32(修订版)

1.5实现一个优先级队列问题怎样实现一个按优先级排序的队列?并且在这个队列上面每次pop操作总是返回优先级高的那个元素解决方案下面的类利用heapq模块实现了一个简单的优先级队列: 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 def pop(self): return heapq.heappop(self._queue)[-1]下面是它的使用方式:
pdf 文件大小:4.84MB