快速排序(python版)
来源:互联网 发布:sql insert into 语法 编辑:程序博客网 时间:2024/05/16 12:48
#!coding:utf8
def quicksort(list_num, left, right):
if left > right:
return
low = left
high = right
privot= list_num[left]
while low<high:
while low < high and list_num[high] > privot:
high-=1
if low < high:
list_num[low] = list_num[high]
while low < high and list_num[low] <= privot:
low+=1
if low < high:
list_num[high] = list_num[low]
list_num[low] = privot
quicksort(list_num, left, low-1)
quicksort(list_num, low+1, right)
if __name__ == "__main__":
test = [7,2,1,6,5,4,4,2]
quicksort(test,0, len(test)-1)
def quicksort(list_num, left, right):
if left > right:
return
low = left
high = right
privot= list_num[left]
while low<high:
while low < high and list_num[high] > privot:
high-=1
if low < high:
list_num[low] = list_num[high]
while low < high and list_num[low] <= privot:
low+=1
if low < high:
list_num[high] = list_num[low]
list_num[low] = privot
quicksort(list_num, left, low-1)
quicksort(list_num, low+1, right)
if __name__ == "__main__":
test = [7,2,1,6,5,4,4,2]
quicksort(test,0, len(test)-1)
0 0
- 快速排序(python版)
- 快速排序 python版
- Python版快速排序算法
- Python--排序--快速排序
- [排序] 快速排序(Python)
- Python版插入排序,归并排序,快速排序
- python快速排序
- 快速排序Python实现
- python快速排序
- 快速排序(python)
- python实现快速排序
- Python实现快速排序
- python 实现快速排序
- Python 快速排序
- python快速排序
- 快速排序 python
- 学习python 快速排序
- Python实现快速排序
- TabHost的使用
- 2016 ACM/ICPC Dalian Online-1006 Football Games
- 设计模式之-工厂模式
- 一些资源
- ubuntu中遇到的问题
- 快速排序(python版)
- Android第一行代码学习笔记二----活动
- 51nod 1348【next_permutation】
- Python标准库中一些模块
- iOS项目拆分:数据本地持久化(2)
- 正则表达式语法
- 设置UIImagePickerController里面的返回按钮的样式图片
- 实现LRU的两种方法---python实现
- Spring+iBatis+Atomikos实现JTA事务