1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
| ''' 可以先温习一下树的路径8.2
输入: 5 3 46 23 26 24 10 5 4 3 输出: 24 23 10 46 23 10 26 10
'''
addr = [0] def Insert(heap,item): if heap[0] >= item: print('小于哨兵!') return if addr[0] == 0: heap[1] = item addr[0] += 1 return i = addr[0] + 1 while heap[i//2] >= item: heap[i] = heap[i//2] i //= 2 heap[i] = item addr[0] += 1
def main(H,MinValue=0,list_=[]): [n,m] = H[0] heap = [None] * (n+1) heap[0] = MinValue for i in H[1]: Insert(heap,i) for i in H[2]: while i >= 1: list_.append(heap[i]) i //= 2 list_.append(' --- ') print(list_) return list_ if __name__ == '__main__': h = [[5, 3], [46 ,23 ,26 ,24 ,10], [5, 4, 3]] main(h)
global a_ a_ = 0 def aa(b=[]): if a_ == 0: print('\n\n!!!!',a_) aa()
|