创建堆 heapq有两种方式创建堆, 一种是使用一个空列表,然后使用heapq.heappush()函数把值加入堆中,另外一种就是使用heap.heapify(list)转换列表成为堆结构 #创建堆方法1import heapqlist=[12,1,53,33,123,2,52,98]heap=[]#将List中各元素依次放入堆中for item in list: heapq.heappush(heap,item)#print(heap[0]) #打印出堆中最小值print([heapq.hea…