用python实现归并排序
来源:互联网 发布:网上淘宝兼职可靠吗 编辑:程序博客网 时间:2024/05/22 10:51
'''Created on 2017-1-6@author: admin'''from builtins import range, intdef mergeSort(source,start,end): if(start>=end): return middle=int((start+end)/2) mergeSort(source, start, middle) mergeSort(source, middle+1, end) merge(source, start, end)def merge(source,start,end): middle=int((start+end)/2) sortedArray=[] i,j=start,middle+1 while i<=middle: if(j>end):break; if(source[i]>source[j]): sortedArray.append(source[j]) j=j+1 else: sortedArray.append(source[i]) i=i+1 if(i<=middle): for ii in range(i,middle+1): sortedArray.append(source[ii]); if(j<=end): for jj in range(j,end+1): sortedArray.append(source[jj]) x=0 for i in range(start,end+1): source[i]=sortedArray[x] x=x+1if __name__ == '__main__': source=[4,1,9,2,8,7,3,6] mergeSort(source,0,len(source)-1) for i in range(0,len(source)): print(source[i], end=',')
0 0
- 用python实现归并排序
- 用python实现归并排序
- python实现归并排序
- Python 实现归并排序
- python实现归并排序
- Python实现归并排序
- python实现归并排序
- Python实现归并排序
- python实现归并排序
- 归并排序的Python实现
- 归并排序及Python实现
- 利用Python实现归并排序
- 归并排序实现(python)
- 归并排序详解(python实现)
- 使用python实现归并排序
- 归并排序的Python实现
- 用Python实现八大排序算法--归并排序
- python实现快速排序和归并排序
- php + nginx 编译安装
- HeadFirst设计模式(策略模式Strategy)
- 默认(1sp = 1dp) , sp:带缩放的dp(手动改变系统字体大小)
- java快速排序算法
- bochs调试指令
- 用python实现归并排序
- 判断一个单链表是否有环及环的链接点
- GNU Linux高并发性能优化方案
- ifconfig相关
- asp 创建和读取xml文件
- 项目路径问题
- 排序算法(一)之3种简单排序(选择,冒泡,直接插入)
- SVN服务器的搭建与使用(二)
- Android Studio 查看整个项目的放法数