Flask接口签名sign原理与实例代码浅析
278
2022-08-26
python实现排序算法(python排序算法详解)
算法设计与分析的作业,使用python实现,简单记录一下
冒泡排序 BubbleSort
#从小到大排序def BubbleSort(waitsortlist): for i in range(0,len(waitsortlist)-1): for j in range(0,len(waitsortlist)-1-i): if waitsortlist[j+1] 选择排序 SelectionSort def SelectionSort(waitsortlist): for i in range(0,len(waitsortlist)-1): min=i for j in range(i+1,len(waitsortlist)): if waitsortlist[j] 验证上面两个算法正确性: def main(): waitsortlist=[2,1,6,5,8,9,4] SelectionSort(waitsortlist) # BubbleSort(waitsortlist) print(waitsortlist) 快速排序 QuickSort def QuickSort(waitsortlist,left,right): if left>right: return left_index,right_index=left,right temp=waitsortlist[left] while left_index!=right_index: while left_index 归并排序 MergeSort def merge(waitsortlist,left,might,right): left_index,right_index=left,might+1 temp=[] while left_index<=might and right_index<=right: if waitsortlist[left_index] 验证上面两个算法正确性: def main(): waitsortlist = [2, 1, 6, 5, 8, 9, 4] QuickSort(waitsortlist,0,len(waitsortlist)-1) print(waitsortlist) waitsortlist = [2, 1, 6, 5, 8, 9, 4] mergeSort(waitsortlist, 0, len(waitsortlist) - 1) print(waitsortlist) return Over
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~