import random import time from heapq import heappush, heappop def heapsort(iterable): h = [] for value in iterable: heappush(h, value) return [heappop(h) for i in range(len(h))] if __name__=="__main__": time_start = time.time() array = [random.randrange(1, 1000) for i in range(random.randrange(1, 1000000))] heapsort(array) print(array) print("时间",time.time()-time_start)