python 基数排序
2021-06-20 11:03
标签:htm [] git array radix append dig pen ret python 基数排序 标签:htm [] git array radix append dig pen ret 原文地址:https://www.cnblogs.com/sea-stream/p/9689064.htmldef 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爬虫与反爬虫(7)
下一篇:python 插值查找