【发布时间】:2013-05-25 18:37:45
【问题描述】:
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
代码的工作: 我将代码的输入作为无序子列表提供,其中列表中的子列表按降序排列,而链表的其余部分按升序排列..
该代码适用于以下输入 1, 2, 3, 4 ,5, 9, 8, 7, 10 和 1,10,9,8,7,6,5.. 即中间和末尾的未排序列表,但如果列表不起作用对于 3,2,1,4,5,6 等输入,在开始时未排序! 谁能帮帮我。。
【问题讨论】:
-
我认为添加一些 cmets 和/或描述排序应该如何工作会有所帮助。这是您自己的自定义排序算法,还是您尝试实现其中一种众所周知的排序算法?
标签: python sorting linked-list sublist