python实现快速排序
2017-01-06 13:51
417 查看
''' Created on 2017-1-6 @author: admin ''' def quickSort(source,start,end): if start==end: return index=shuffle(source, start, end) if(index-1>start): quickSort(source, start,index-1) if index+1<=end: quickSort(source, index+1, end) def shuffle(source,start,end): leftIndex=start; rightIndex=end sepValue=source[start] directionRight=True while leftIndex!=rightIndex: if directionRight: if sepValue>source[rightIndex]: source[leftIndex]=source[rightIndex] leftIndex=leftIndex+1 directionRight=False else: rightIndex=rightIndex-1 else: if sepValue<=source[leftIndex]: source[rightIndex]=source[leftIndex] rightIndex=rightIndex-1 directionRight=True else: leftIndex+=1 source[leftIndex]=sepValue; return leftIndex if __name__ == '__main__': source=[7,3,2,9,4,8,5,6,1] quickSort(source,0,len(source)-1) for i in range(0,len(source)): print(source[i],end=',')
相关文章推荐
- Python练习实例9
- 【转】使用Python matplotlib绘制股票走势图
- Python的Numpy库中的 nonzero函数,及应用在 hardlim硬限幅函数中
- Python练习实例8
- windows环境下安装selenium
- Ubuntu16.04 Eclipse中Python开发环境搭建
- 冒泡排序python实现
- python 编码转换 unicode和encode作用
- Python取周的相关信息的几个函数
- numpy 学习2
- Python 基础知识之字符串处理
- python发送各类邮件的主要方法
- python之基础篇(九)——异常
- Python练习实例7
- 【Python爬虫系列】Python 爬取上海链家二手房数据
- 用python实现归并排序
- python3学习笔记(贴别人的文章)
- python学习三
- 详解Python中的相对导入和绝对导入
- Python练习实例6