1 Star 0 Fork 0

dzc/Python-1

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Counting-sort.py 574 Bytes
一键复制 编辑 原始数据 按行查看 历史
Ashish Kumar 提交于 2019-10-07 13:01 +08:00 . cs.py
# counting sort
l = [] # l is the list
n = int(input("Enter number of elements in the list: "))
highest = 0
for i in range(n):
temp = int(input("Enter element" + str(i + 1) + ': '))
if temp > highest:
highest = temp
l += [temp]
def counting_sort(l, h):
bookkeeping = [0 for i in range(h + 1)]
for i in l:
bookkeeping[i] += 1
L = []
for i in range(len(bookkeeping)):
if bookkeeping[i] > 0:
for j in range(bookkeeping[i]):
L += [i]
return L
print(counting_sort(l, highest))
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/sdredboy/Python-1.git
git@gitee.com:sdredboy/Python-1.git
sdredboy
Python-1
Python-1
master

搜索帮助