python 基数排序

2021-06-20 11:03

阅读:506

标签:htm   []   git   array   radix   append   dig   pen   ret   

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 基数排序

标签:htm   []   git   array   radix   append   dig   pen   ret   

原文地址:https://www.cnblogs.com/sea-stream/p/9689064.html


评论


亲,登录后才可以留言!