python算法实践4-快速排序
2010-03-16 15:03
330 查看
#快速排序 def Partition(mylist, low, high): tmp = mylist[low] while low < high: while low < high and mylist[high] >= tmp: high = high - 1 if low < high: mylist[low] = mylist[high] low = low + 1 while low < high and mylist[low] <= tmp: low = low + 1 if low < high: mylist[high] = mylist[low] high = high - 1 mylist[low] = tmp return low def QuickSort(mylist, low, high): if low < high: pivotpos = Partition(mylist, low, high) QuickSort(mylist, low, pivotpos - 1) QuickSort(mylist, pivotpos + 1, high) mylist0 = [11, 10, 3, 12, 33, 1000, 1, 333, -11] QuickSort(mylist0, 0, len(mylist0) - 1) print(mylist0)
相关文章推荐
- Python程序设计与算法基础教程·第八章上机实践
- 机器学习算法与Python实践(7) - 自组织映射算法(SOM)
- 算法 python实现(三) 快速排序
- python算法实践5-直接选择排序
- Python之排序算法:快速排序与冒泡排序
- 【Python排序搜索基本算法】之快速排序(QuickSort)
- Algorithm: quick sort implemented in python 算法导论 快速排序
- python算法实践1-直接插入排序
- Python算法 归并排序和快速排序
- 算法实践篇-基于快速排序原理的选择第i小元选择算法
- 数据结构&算法实践-Python——序章
- 【算法——Python实现】快速排序的优化:三路快速排序及Leetcode题目应用
- python写算法之快速排序
- Python程序设计与算法基础教程·第三章上机实践
- Python算法实践-学习记录(1)
- python xgboost算法实践
- 数据结构&算法实践-Python——序章
- python算法实践6-堆排序
- Python程序设计与算法基础教程·第四章上机实践
- python算法--快速排序详细实现