python优先级队列如何最大值优先
发布网友
发布时间:2022-05-04 16:31
我来回答
共2个回答
热心网友
时间:2022-05-10 21:04
def heapq_int():
heap = []
#以堆的形式插入堆
heapq.heappush(heap,10)
heapq.heappush(heap,1)
heapq.heappush(heap,10/2)
[heapq.heappush(heap,i) for i in range(10)]
[heapq.heappush(heap,10 - i) for i in range(10)]
#最大的10个元素
print heapq.nlargest(10,heap)
#输出所有元素
print [heapq.heappop(heap) for i in range(len(heap))]
热心网友
时间:2022-05-10 22:22
啥???????队列默认就有优先级