Python基数排序是一种非比较整数排序算法,其原理是将整数按位数切割成不同的数字,然后按每个位数分别比较。下面web建站小编给大家简单介绍一下具体代码!
Python代码实现基数排序算法
def countingSort(array, place): size = len(array) output = [0] * size count = [0] * 10 for i in range(0, size): index = array[i] // place count[index % 10] += 1 for i in range(1, 10): count[i] += count[i - 1] i = size - 1 while i >= 0: index = array[i] // place output[count[index % 10] - 1] = array[i] count[index % 10] -= 1 i -= 1 for i in range(0, size): array[i] = output[i] def radixSort(array): # Get maximum element max_element = max(array) place = 1 while max_element // place > 0: countingSort(array, place) place *= 10 data = [121, 432, 564, 23, 1, 45, 788] radixSort(data) print(data)
python中pip出现"ParseException(s, l, str(ve))"的错误解决方法
上面是“如何利用Python代码实现基数排序算法”的全面内容,想了解更多关于 前端知识 内容,请继续关注web建站教程。
当前网址:https://ipkd.cn/webs_14094.html
workflows工作流
羚羊安上小白兔的门牙ComfyUI工作流
一个以破旧的怀旧史努比玩偶
一个熙熙攘攘的市场场景,里面摆满了南瓜
广阔的沙漠中矗立着一个生锈的巨大头盔
一只穿着黑色蝴蝶结西装可爱橙色小猫
一条色彩斑斓的超现实小孔雀鱼ComfyUI工作流
一辆停在混凝土墙前运动型SUV捷豹概念车
红伞伞蓝杆杆云南蘑菇群ComfyUI工作流
猜你喜欢
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!