def sublist(head):
current=head
#temp=current #If my list is 3->2->1->4->5->6 it goes into an infinite loop
while ((current.next is not None) and current.value < current.next.value):
temp=current
current=current.next
start=current
while ((current.next is not None) and current.value > current.next.value):
current=current.next
last=current.next
current.next=None
first=reverse_linked_list(start)
temp.next=first
while first.next is not None:
first=first.next
first.next=last
while head:
print head.value
head=head.next
return head
代碼的工作: 我給輸入代碼爲無序子列表,其中列表中的子列表是decending秩序和鏈接列表的其餘部分按升序爲了..排序的子列表的鏈接列表的Python
代碼工作,用於輸入像 1,2,3,4,5,9%,8,7,10和1,10,9,8,7,6,5 ..即一個未排序列表在中間和結束,但它不起作用,如果列表未分類在開始輸入像3,2,1,4,5,6! 誰能幫我請..
我認爲這將有所幫助,如果你添加一些評論和/或描述如何排序應該工作。這是你自己的自定義排序算法還是你想實現其中一個知名的? –
相關:[用於Python中單連接線性列表的Mergesort算法](https://gist.github.com/zed/5651186) – jfs