Пример #1
0
        while(tmp.next!=pivot):
            tmp = tmp.next
        tmp.next = None # need to break the link for the first half
        newHead = quicksortHelper(newHead,tmp)
        tmp = getTail(newHead)  # the tail of the first half should be re-fetch
        tmp.next = pivot
        
    if newTail!=pivot:
        pivot.next = quicksortHelper(pivot.next,newTail)
        
    return newHead

def quickSort(head):
    if head:
        tail = getTail(head)
        return quicksortHelper(head,tail)
    
    



aList = LinkedList()
aList.add(9)
aList.add(4)
aList.add(8)
aList.add(3)
aList.add(7)
aList.add(6)
print aList
print aList.displayLinkedListFromNode(aList.head.next)
print aList.displayLinkedListFromNode(quickSort(aList.head))
                head2.next = curr2
                curr2 = None
            elif curr2.next and curr1.value<curr2.next.value:
                tmp = curr2.next
                curr2.next = curr1
                curr1 = curr1.next
                curr2.next.next = tmp
                curr2 = None
            elif not curr2.next:
                curr2.next = curr1
                curr1 = curr1.next
                curr2.next.next = None
                curr2 = None
            else:
                curr2 = curr2.next
    return head2


aList = LinkedList()
aList.add(9)
print aList.displayLinkedListFromNode(insertionSort(aList.head))
aList.add(4)
print aList.displayLinkedListFromNode(insertionSort(aList.head))
aList.add(8)
aList.add(3)
aList.add(7)
aList.add(6)
print aList
print aList.displayLinkedListFromNode(insertionSort(aList.head))