title: Sorting a Sublist in a Linked List Python
body: <pre><code>def sublist(head):
      current=head
      #temp=current #If my list is 3-&gt;2-&gt;1-&gt;4-&gt;5-&gt;6 it goes into an infinite loop
      while ((current.next is not None) and current.value &lt; current.next.value ):
          temp=current
          current=current.next
      start=current
      while ((current.next is not None) and current.value &gt; 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
  </code></pre>
  
  <p>Working of the code:
  I give the input to the code as a unordered sublist where sublist within the list is in decending order and the rest of the linked list is in ascending order..</p>
  
  <p>The code works for inputs like 
  1, 2, 3, 4 ,5, 9, 8, 7, 10 and 1,10,9,8,7,6,5.. i.e an unsorted list in the middle and the end but it doesnt work if the list is unsorted at the beginning for inputs like 3,2,1,4,5,6! 
  Can anyone help me out Please.. </p>