python实现bucket排序算法

2022-04-14 00:00:00 python 算法 排序

python实现bucket排序算法,算法效率不错

"""
皮蛋编程(https://www.pidancode.com)
创建日期:2022/4/2
功能描述:python实现bucket排序算法
"""
def bucketSort(a, n, buckets, m):
    for j in range(m):
        buckets[j] = 0
    for i in range(n):
        buckets[a[i]] += 1
    i = 0
    for j in range(m):
        for k in range(buckets[j]):
            a[i] = j
            i += 1

相关文章