计数排序

博客地址:https://www.cnblogs.com/zylyehuo/

# _*_coding:utf-8_*_

import random


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


li = [random.randint(0, 10) for _ in range(50)]
print(li)

count_sort(li)
print(li)

posted @ 2023-08-15 10:26  zylyehuo  阅读(6)  评论(0编辑  收藏  举报