欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 新闻 > 社会 > 排序算法思维导图

排序算法思维导图

2025/1/8 2:44:18 来源:https://blog.csdn.net/qq_65009672/article/details/144094958  浏览:    关键词:排序算法思维导图

 

 

 

 冒泡排序

def bubble_sort(alist):j = 0while j < len(alist):i = 0while i < len(alist) - 1:if alist[i] > alist[i+1]:alist[i], alist[i+1] = alist[i+1], alist[i]i += 1j += 1li = [34,556,235,7,56,45,63,35,23,4,875]
bubble_sort(li)
print(li)

 选择排序

def select_sort(alist):i = 0while i < len(alist) - 1:min_idex = ij = i+1while j < len(alist):if alist[min_idex] > alist[j]:min_idex = jj += 1if min_idex != i:alist[i], alist[min_idex] = alist[min_idex],alist[i]i += 1li = [34,556,235,7,56,45,63,35,23,4,875]
select_sort(li)
print(li)

 直接插入排序

def insert_sort(alist):i = 1while i < len(alist):temp = alist[i]j = iwhile temp < alist[j-1] and j>0:alist[j] = alist[j-1]j -= 1alist[j] = tempi += 1li = [34,556,235,7,56,45,63,35,23,4,875]
insert_sort(li)
print(li)

 快速排序

def part(alist,left,right):p = alist[left]while left < right:while alist[right] >= p and left < right:right -= 1alist[left] = alist[right]while alist[left] <= p and left < right:left += 1alist[right] = alist[left]alist[left] = preturn leftdef quick_sort(alist,left,right):if left < right:p_idex = part(alist,left,right)quick_sort(alist,left,p_idex-1)quick_sort(alist,p_idex+1,right)li = [324,5346,74,523,857,6,2345,457,789]
quick_sort(li,0,len(li)-1)
print(li)

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com