计数排序

计数排序

import  random

def count_sort(li, count=100):
    count = [0 for _ in range(count+1)]
    for val in li:
        count.append(val)
    li.clear()
    for ind, val in enumerate(count):
        for i in range(val):
            li.append(ind)

li = [random.randint(0, 100) for _ in range(1000)]
count_sort(li)
print(li)

  

posted @ 2022-03-26 13:49  KYZH  阅读(17)  评论(0编辑  收藏  举报