python--归并排序
2017-10-24 11:20
288 查看
***一直切分到只有2个元素的左右两边,然后对其进行排序合并,新生成的数组和其他切分的数据在进行排序合并。*** def sortIntegers2(self,array): array_len = len(array) if array_len<2: return array mid = array_len//2 left = self.sortIntegers2(array[:mid]) right = self.sortIntegers2(array[mid:]) res = [] while len(left)>0 and len(right)>0: if left[0]<right[0]: res.append(left.pop(0)) else: res.append(right.pop(0)) if len(left)>0: res.extend(left) else: res.extend(right) return res
相关文章推荐
- [硕.Love Python] MergeSort(归并排序)
- 归并排序 @ Python
- 归并排序(Python)
- 快速排序 and 归并排序(python)
- 排序算法Python(冒泡、选择、快速、插入、希尔、归并排序)
- 使用python实现归并排序
- python实现归并排序
- [硕.Love Python] MergeSort(归并排序)
- Python - 归并排序
- python 归并排序
- 归并排序 python版
- 快速排序,归并排序,堆排序python实现
- python数据结构与算法----归并排序
- 【程序员笔试面试必会——排序①】Python实现 冒泡排序、选择排序、插入排序、归并排序、快速排序、堆排序、希尔排序
- 归并排序--Python
- python归并排序
- Python实现快速,冒泡和归并排序
- 4000 【数据结构笔记】归并排序(merge_sort)-- python2.7
- python中实现二分查找,插入排序,归并排序,快速排序
- 排序算法总结(归并排序、快速排序)(python实现)