import heapq
def heapsort(items):
heap = []
for item in items:
heapq.heappush(heap, item)
return [heapq.heappop(heap) for _ in range(len(heap))]
nums = [1, 3, 5, 7, 9, 2, 4, 6, 8, 0]
print(heapsort(nums))
python堆排序
最新推荐文章于 2020-12-07 11:06:58 发布