mergesort in python
2014-05-04 21:47
267 查看
def mergesort(List): """ input : List, an integer list output : an sorted integer list """ n = len(List) if n == 0 or n==1: return List first = mergesort(List[:n/2]) second = mergesort(List[n/2:]) i=0 j=0 output = [] while True: if first[i]<second[j]: output.append(first[i]) i += 1 else: output.append(second[j]) j += 1 if i >= len(first): output += second[j:] break if j >= len(second): output += first[i:] break return output
相关文章推荐
- Python 迭代器
- [Python]读取xls并搜索文件夹,归类同名文件
- python yeild使用
- Python字符串
- 突破python爬虫限制种种
- Jython 和 Python 对比
- python unittest 测试框架
- Python -- 游戏开发 -- PyGame的使用
- Python -- Windows编程 -- 注册表
- Python -- Gui编程 -- Win32API的使用
- Python -- Gui编程 -- MFC的使用
- python 添加路由
- Python数字
- Python -- Gui编程 -- Tkinter的使用 -- 菜单与画布
- Python -- Gui编程 -- Tkinter的使用 -- 对话框消息框
- Python -- Gui编程 -- Tkinter的使用 -- 基本控件
- Python -- 算法实现
- Python 使用 subprocess 调用外部命令
- 递归函数
- Python -- Gui编程 -- Qt库的使用 -- 配置资源文件