python基数排序算法演示代码
python基数排序算法演示代码,随机生成了9个数,然后对齐进行排序
""" 皮蛋编程(https://www.pidancode.com) 创建日期:2022/4/2 功能描述:python基数排序算法演示代码 """ from random import randint def main(): arr = [randint(1, 99999999) for _ in range(9)] for k in range(8): S = [[] for _ in range(10)] for j in arr: S[int(j / (10 ** k) % 10)].append(j) arr = [a for b in S for a in b] for i in arr: print(i) main()
输出结果:
11361415
22068943
33397703
36089598
47149224
53983570
54806943
66386753
90023401
代码在python3.9下测试通过
相关文章