python: 快速排序
2015-12-23 21:41
585 查看
python: 快速排序
标签:python 快速排序by 小威威
今天我用python写了快排的排序,代码如下:
#!/usr/bin/python3 # Filename: quicksort.py def quicksort(list, big, small): if big >= small: return key = big key2 = small while big != small: while (small > big): if list[small] < list[key]: break small -= 1 while (big <= small): if big == small: temp = list[big] list[big] = list[key] list[key] = temp break if list[big] > list[key]: break big += 1 temp = list[big] list[big] = list[small] list[small] = temp quicksort(list, key, big-1) quicksort(list, big+1, key2) list = input().split() list = [int(i) for i in list] quicksort(list, 0, len(list)-1) print (list)
以上内容皆为本人观点,欢迎大家提出批评和指导,我们一起探讨。
相关文章推荐
- python学习之数字
- Python学习笔记 数据类型
- python常见操作
- 几个python练习题
- tf–idf算法解释及其python代码实现(上)
- python pydot安装
- python pip安装出现错误
- Python学习笔记----模块
- python学习笔记 python开发环境的搭建
- leetcode之Pascal's Triangle
- Python数据分析入门之pandas基础总结
- python 运行不过去SyntaxError: Non-ASCII character '\xc2' in file
- Python声音处理入门
- python __slots__方法
- python property
- win下实现Python通过rpy2调用R
- Python基础教程之第2章 列表和元组
- python collections.Counter笔记
- 机器学习学习笔记(二)——回归
- python urllib 和urllib2的区别