Python 实现选择排序
来源:互联网 发布:ubuntu iso安装教程 编辑:程序博客网 时间:2024/06/06 15:36
# Sorts a sequence in ascending order using the selection sort algorithmdef selectionSort(theSeq): n = len(theSeq) for i in range(n-1): # Assume the ith element is the smallest smallNdx = i # Determine if any other element contains a smaller value for j in range(i+1, n): if theSeq[j] < theSeq[smallNdx]: smallNdx = j # Swap the ith value and smallNdx value only if the smallest value is # not already in its proper position. Some implementations omit testing # the condition and always swap the two values if smallNdx != i: tmp = theSeq[i] theSeq[i] = theSeq[smallNdx] theSeq[smallNdx] = tmp
In [2]: theSeq = [3,7,5,2,9,10]In [3]: selectionSort(theSeq)In [4]: theSeqOut[4]: [2, 3, 5, 7, 9, 10]
0 0
- Python 实现选择排序
- python 实现选择排序
- 选择排序python实现
- Python实现选择排序
- python选择排序实现法
- 利用Python实现选择排序
- 选择排序(python实现)
- 用python实现选择排序
- 简单选择排序 Python实现
- python实现插入排序,选择排序
- python实现插入排序和选择排序
- python 实现插入排序,冒泡排序,快速排序,选择排序
- python算法--置换选择排序详细实现
- (二)选择排序-python实现
- python 实现冒泡,选择,插入排序
- 选择排序实现及优化--python
- C/Python实现直接选择排序
- 选择排序算法(python实现)
- Intel® Integrated Performance Primitives(IPP)的配置方法及函数库初探(Image Processing)
- 通过一个翻译程序复习下 抓数据、正则表达式等
- sublime中Zen Coding插件快捷编码
- ZigZag Conversion
- Junit spring 多线程测试
- Python 实现选择排序
- php基础教程——2创建模板、处理表单
- 降低漏洞风险的六大法宝!
- linux Crontab定时运行JAR
- Oracle分析函数使用总结
- 使用Python进行模拟登陆
- 个人心得
- 全球wcdma运营频段
- vi编辑器使用总结