python 内置速度最快算法(堆排)

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)
原文地址:https://www.cnblogs.com/renfanzi/p/6013649.html