コード例 #1
0
def main():
    data = [0] * 100
    size = int(input("Please enter an number :"))
    print('The origin data is ')
    inputarr(data, size)

    show_data(data)

    radix(data, size)
コード例 #2
0
def main():
    data = [0] * 100
    size = int(input('Please enter a array array size (under 100) :'))
    inputarr(data, size)

    print('The origin data you enter was :')
    show_data(data)

    print('The sorting process was :')
    quick(data, size, 0, size - 1)

    print("Data after sorting :")
    show_data(data)
コード例 #3
0
def shell(data):
    k = 1
    tmplen = len(data) // 2
    while tmplen != 0:
        for i in range(tmplen, len(data)):
            tmp = data[i]  # use tmp to store data
            j = i - tmplen

            while tmp < data[j] and j >= 0:  # insert sort
                data[j + tmplen] = data[j]
                j = j - tmplen

            data[tmplen] = tmp

        print('The %d time sorting is :' % k, end='')
        k += 1
        show_data(data)

        tmplen = tmplen // 2
コード例 #4
0
def radix(data, size):
    n = 1  # where n is an odd number
    while n < 100:
        tmp = [[0] * 100
               for row in range(10)]  # set an tmp array tmp_array[0~9] = 0

        for i in range(size):
            m = (data[i] // n) % 10  # mod(m) is n
            tmp[m][i] = data[i]  # store data[i] in tmp_array

        k = 0
        for i in range(10):
            for j in range(size):
                if tmp[i][
                        j] != 0:  # without initial value 0, every none-zero value is
                    data[k] = tmp[i][j]  # what we need

                    k += 1

        print('After %d th time sorting: ' % n, end='')

        show_data(data)
        n = 10 * n
コード例 #5
0
data = [16, 25, 39, 27, 12, 8, 45, 63]


def shell(data):
    k = 1
    tmplen = len(data) // 2
    while tmplen != 0:
        for i in range(tmplen, len(data)):
            tmp = data[i]  # use tmp to store data
            j = i - tmplen

            while tmp < data[j] and j >= 0:  # insert sort
                data[j + tmplen] = data[j]
                j = j - tmplen

            data[tmplen] = tmp

        print('The %d time sorting is :' % k, end='')
        k += 1
        show_data(data)

        tmplen = tmplen // 2


print("The origin data is :")
show_data(data)

shell(data)
print("Data after sorting :")
show_data(data)