【Python排序搜索基本算法】之选择排序
2013-07-21 19:39
651 查看
选择排序就是第n次把序列中最小的元素排在第n的位置上,一旦排好就是该元素的绝对位置。代码如下:
转载请注明:转自 /article/1349978.html
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)
转载请注明:转自 /article/1349978.html
相关文章推荐
- 【Python排序搜索基本算法】之选择排序
- 【Python排序搜索基本算法】之希尔排序
- Python排序搜索基本算法之归并排序实例分析
- Python排序搜索基本算法之插入排序实例分析
- 【Python排序搜索基本算法】之Dijkstra最短路径算法(Dijkstra's Shortest-Path Algorithm)
- 【Python排序搜索基本算法】之插入排序
- 【Python排序搜索基本算法】之无向图的最小割&Karger算法(Graphs and Minimum Cuts & Karger's Min-Cut Algorithm)
- 【Python排序搜索基本算法】之快速排序(QuickSort)
- 【Python排序搜索基本算法】之归并排序
- Python排序搜索基本算法之选择排序实例分析
- 【Python排序搜索基本算法】之二叉树的遍历
- 【Python排序搜索基本算法】之Dijkstra算法
- 【Python排序搜索基本算法】之冒泡排序
- 【Python排序搜索基本算法】之快速排序
- 【Python排序搜索基本算法】之Prim算法
- 【Python排序搜索基本算法】之拓扑排序
- Python排序搜索基本算法之冒泡排序实例分析
- 【Python排序搜索基本算法】之拓扑排序
- 【Python排序搜索基本算法】之Prim算法
- 【Python排序搜索基本算法】之归并排序&分治法(Merge Sort and Divide & Conquer)