为什么 heappush 采用 3 个参数 arr[i].data、i 和 arr[i]。为什么取i为参数 一般只取一个参数 是合并k个排序的链表的代码
def mergeKLists(arr,K):
# code here
# return head of merged list
heap = []
head = tail = Node(0)
for i in range(K):
heapq.heappush(heap,(arr[i].data,i,arr[i]))
while heap:
node = heapq.heappop(heap)
node = node[2]
tail.next = node
tail = tail.next
if node.next:
i += 1
heapq.heappush(heap,(node.next.data,i,node.next))
return head.next