0
>>> import heapq as h
>>> l = [1,3,6,2,9]
>>> dir(h) ['__about__', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__',
'__spec__', '_heapify_max', '_heappop_max', '_heapreplace_max',
'_siftdown', '_siftdown_max', '_siftup', '_siftup_max', 'heapify',
'heappop', 'heappush', 'heappushpop', 'heapreplace', 'merge',
'nlargest', 'nsmallest']
>>> h._heapify_max(l)
>>> l [9, 3, 6, 2, 1]
>>> l [1, 3, 6, 2]
>>> h.heappush(l,9)
>>> l [1, 3, 6, 2, 9]
>>> h._heapify_max(l)
>>> l [9, 3, 6, 2, 1]
>>> h._heappop_max(l) 9
>>> l [6, 3, 1, 2]
>>> h.heappush(l,9)
>>> l [6, 3, 1, 2, 9]
>>>

在此之后,我应该如何插入 9 到实际位置,即第 0 个索引?

4

0 回答 0