def TimSort(array,n):
    for i in range(0,n,RUN):
        Sorts.insertionSort(array,i,min(i+RUN-1,n-1))
    size=RUN
    while size < n:
        for x in range(0,n,size*2):
            array[x:x+2*size]=Sorts.merge(array[x:x+size],array[x+size:x+2*size])
        size*=2
Exemplo n.º 2
0
def sortData(unsortedList):
    """
    This function will run the sorting algortihms, and track their data.
    Input: unsorted list
    Output: data from the sorting algorithms
    """
    # We will begin with the data from the bubble sort
    bubbleSortData = []
    bubbleSortOptData = []
    selectionSortData = []
    insertionSortData = []

    # The range of testing will begin at zero
    testRange = 0

    for i in range(len(unsortedList) + 1):
        bubbleSortCount = Sorts.bubbleSort(unsortedList[:testRange])
        bubbleSortData.append(bubbleSortCount)

        bubbleSortOptCount = Sorts.bubbleSortOpt(unsortedList[:testRange])
        bubbleSortOptData.append(bubbleSortOptCount)

        selectionSortCount = Sorts.selectionSort(unsortedList[:testRange])
        selectionSortData.append(selectionSortCount)

        insertionSortCount = Sorts.insertionSort(unsortedList[:testRange])
        insertionSortData.append(insertionSortCount)
        testRange += 1

    # Write the sort data to text file
    writeSortDataToText(bubbleSortData, bubbleSortOptData, selectionSortData,
                        insertionSortData)