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工作流
小孩手握锤子顽皮搞笑卡通3d形象
梦幻中的一只猫咪ComfyUI工作流
一支令人难忘的狙击步枪ComfyUI工作流
在月球上穿着太空服的宇航员
在森林中心有一座蛇形的房子ComfyUI工作流
一个白色的咖啡杯,蒸汽从杯子里冒出来
穿着蘑菇帽的小蚂蚁探险家ComfyUI工作流
一个外国人在吹奏萨克斯ComfyUI工作流
猜你喜欢
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!