1. 程式人生 > >python 基數排序

python 基數排序

radi python list div class lis hlist buck ear

def radix_sort(array):

    bucket, digit = [[]], 0

    while len(bucket[0]) != len(array):

        bucket = [[], [], [], [], [], [], [], [], [], []]

        for i in range(len(array)):

            num = (array[i] // 10 ** digit) % 10

            bucket[num].append(array[i])

        array.clear()

        for i in range(len(bucket)):

            array += bucket[i]

        digit += 1

    return array

hlist = radix_sort([4,5,6,7,3,2,6,9,8])
 
print(hlist)

  

python 基數排序