Counting Sort. Θ(n+k)

from random import choices  

scope = 50
amount = 100
source = choices(range(scope),k=amount)
counter = [0]*scope

for x in source:
    counter[x] += 1

for i in range(1, scope):
    counter[i] += counter[i-1]

destination = [0]*amount

for x in reversed(source):
    # index = count-1
    destination[counter[x]-1] = x    #
    counter[x] -= 1

你可能感兴趣的:(Counting Sort. Θ(n+k))