def heapsort(A:List[int])->List[int]: build_max_heap(A) res = [] for i in range(len(A)-1,0,-1): res.append(A.pop(0)) max_heapify(A,0) return res+A param = [16, 14, 10, 8, 7, 9, 3, 2, 4, 1] result = heapsort(param) print(result) # [16, 14, 10, 9, 8, 7, 4, 3, 2, 1]
← 6.3 建堆 6.5 优先队列→