美文网首页
Counting Sort. Θ(n+k)

Counting Sort. Θ(n+k)

作者: R0b1n_L33 | 来源:发表于2018-03-17 11:48 被阅读2次
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)

      本文链接:https://www.haomeiwen.com/subject/acxjqftx.html