def listmerge(L1, L2):
'''(CustomerNode, CustomerNode) -> CustomerNode
Merge the linked lists headed by L1 and L2 into a single list with ticket_num in
increasing order. Return the head of the merged list.
REQ: Lists headed by L1 and L2 are sorted by ticket_num, all ticket_num values are unique.
'''
current = L1
while current.next != None:
current = current.next
current.next = L2
return L1
客户节点的一个示例类似于LinkedList,但它是这样的:
^{pr2}$基本上我需要优先排序。最小的数字应该是头部。在
到目前为止,我只是做了合并。在
我在想,在合并节点之前,你可以先按你想排序的类别排序,然后用你的
listmerge(L1, L2)
函数进行合并。在假设我们有这些节点:
注意:我已经将
priority
替换为name
现在,我将创建一个列表,其中包含所有这些节点,而不进行任何排序:
^{pr2}$然后我可以继续按我想排序的字段进行排序。我假设按
data
排序:最后,通过迭代
sortedList
并将每个节点传递给listmerge
函数来完成合并。在要显示上述结果的示例:
相关问题 更多 >
编程相关推荐