CountSort in Python


def MyCountSort(a):               #计数排序#
    b=[0]*len(a)
    c=[0]*(max(a)+1)
    for i in range(len(a)):
        c[a[i]] = c[a[i]]+1
    for i in range(1,max(a)+1):
        c[i] = c[i]+c[i-1]
    for i in range(len(a)-1,-1,-1):
        b[c[a[i]]-1] = a[i]
        c[a[i]] = c[a[i]] - 1
    return b

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