BucketSort in Python


def MyBucketSort(a):            #桶排序#  a = [0,1)
    b = [[]] * 10
    result = [0]*len(a)
    k=1
    for i in range(len(a)):
        b[int(10*a[i])] = b[int(10*a[i])] + [a[i]]
    for i in range(len(b)):
        MyInsertSort(b[i])
    for i in range(10):
        temp = b.pop()
        if temp:
            for j in range(len(temp)):
                result[-k] = temp.pop()
                k=k+1
    return result

你可能感兴趣的:(BucketSort in Python)