1. from heapq import heappop, heappush
    2. def heap_sort(array):
    3. """堆排序
    4. Example:
    5. >>> myArray = [36, 25, 48, 12, 25, 65, 43, 57]
    6. >>> [12, 25, 25, 36, 43, 48, 57, 65]
    7. """
    8. h = []
    9. for value in array:
    10. heappush(h, value)
    11. return [heappop(h) for _ in range(len(h))]