【Python排序搜索基本算法】之选择排序
来源:互联网 发布:中北大学软件工程学院 编辑:程序博客网 时间:2024/06/07 17:33
转自 http://blog.csdn.net/littlethunder/article/details/9400083
选择排序就是第n次把序列中最小的元素排在第n的位置上,一旦排好就是该元素的绝对位置。代码如下:
def selectionSort(seq): length=len(seq) for i in range(length): mini=min(seq[i:]) if seq[i]>mini: j=seq.index(mini,i) seq[i],seq[j]=seq[j],seq[i] if __name__=='__main__': seq=[3,4,5,9,3,1,5,7,90,-2,] selectionSort(seq) print(seq)
0 0
- 【Python排序搜索基本算法】之选择排序
- 【Python排序搜索基本算法】之选择排序
- 【Python排序搜索基本算法】之插入排序
- 【Python排序搜索基本算法】之冒泡排序
- 【Python排序搜索基本算法】之快速排序(QuickSort)
- 【Python排序搜索基本算法】之希尔排序
- 【Python排序搜索基本算法】之归并排序
- 【Python排序搜索基本算法】之快速排序
- 【Python排序搜索基本算法】之插入排序
- 【Python排序搜索基本算法】之堆排序
- 【Python排序搜索基本算法】之拓扑排序
- 【Python排序搜索基本算法】之拓扑排序
- 【Python排序搜索基本算法】之Prim算法
- 【Python排序搜索基本算法】之Dijkstra算法
- 基本算法之选择排序
- 【Python排序搜索基本算法】之二叉树的遍历
- 基本算法之简单选择排序算法
- 【Python排序搜索基本算法】之深度优先搜索、广度优先搜索、拓扑排序、强联通&Kosaraju算法
- codeforces 468D Valid Sets
- 第一篇博客
- POJ 3074 suduku
- ACM-数据结构-线段树I
- Hadoop如何Kill指定用户的所有Job
- 【Python排序搜索基本算法】之选择排序
- codeforces 486B OR in Matrix
- HTML学习(二)
- Git add命令详解
- “未声明的标识符:SurfFeatureDetector”问题解决办法
- android selector失效的原因
- ios8 添加新方法记录(连载)
- CentOS下yum安装LAMP
- 点击FrameLayout,使其里面的控件TextView改变颜色