selection sort DEMO(linear complexity)
2015-07-09 08:46
225 查看
#quote from MIT 'introduction to computation and programming using python, Revised' def selSort(L): """Assumes that L is a list of elements that can be compared using >. Sorts L in ascending order""" suffixStart = 0 while suffixStart != len(L): #look at each element in suffix for i in range(suffixStart, len(L)): if L[i] < L[suffixStart]: #swap position of elements L[suffixStart], L[i] = L[i], L[suffixStart] suffixStart += 1
L = [1, 10, 2, 9, 7, 100, 99, 23, 0]
selSort(L)
print L
[0, 1, 2, 7, 9, 10, 23, 99, 100]
相关文章推荐
- gridview整页翻页的滑动,上滑和下滑,适应各种布局
- 关于ExpandableListView用法的一个简单小例子
- A2W、W2A、A2T、T2A、(USES_CONVERSION)
- Android-系统换肤的几种方法
- Tomcat结构
- js用POST方式页面跳转,避免在地址栏中显示传递参数
- 亿级Web系统搭建――单机到分布式集群
- 关于buffer overflow detected 程序崩溃的思考
- Javascript中的scrollLeft,scrollWidth,clientWidth,offsetWidth
- 3D rotate:
- C#中的线程(一)入门
- ASP.NET Web API 2 - 简单Unit Testing
- ibaits2中要注意remapResults-被坑了
- 根据URL的value找rowkey或者其他数据
- Linux运维系统工程师系列---23
- 安装VMware Workstation 10
- MyBatis动态Sql语句
- python,dict的setdefault方法
- numpy中的broadcast
- 7款经典炫酷的HTML5/jQuery动画应用示例及源码