【Python排序搜索基本算法】之冒泡排序
来源:互联网 发布:淘宝网是马云的吗 编辑:程序博客网 时间:2024/06/06 14:04
冒泡排序和选择排序类似,也是第n次把最小的元素排在第n的位置上,也是该元素的绝对位置,只是冒泡排序的过程中,其他的元素也逐渐向自己最终位置逼近。代码如下:
def bubbleSort(seq):length=len(seq)for i in range(length):for j in range(length-1,i,-1):if seq[j-1]>seq[j]:seq[j-1],seq[j]=seq[j],seq[j-1]if __name__=='__main__':seq=[2,9,7,7,4,3,2,-4,54,-7,0]bubbleSort(seq)print(seq)
转载请注明:转自 http://blog.csdn.net/littlethunder/article/details/9400107
- 【Python排序搜索基本算法】之冒泡排序
- 基本算法之冒泡排序
- 【Python排序搜索基本算法】之插入排序
- 【Python排序搜索基本算法】之选择排序
- 【Python排序搜索基本算法】之快速排序(QuickSort)
- 【Python排序搜索基本算法】之希尔排序
- 【Python排序搜索基本算法】之归并排序
- 【Python排序搜索基本算法】之快速排序
- 【Python排序搜索基本算法】之插入排序
- 【Python排序搜索基本算法】之堆排序
- 【Python排序搜索基本算法】之拓扑排序
- 【Python排序搜索基本算法】之选择排序
- 【Python排序搜索基本算法】之拓扑排序
- 基本排序算法之冒泡排序
- 基本排序算法之冒泡排序
- 【Python排序搜索基本算法】之Prim算法
- 【Python排序搜索基本算法】之Dijkstra算法
- 【Python排序搜索基本算法】之二叉树的遍历
- Makefile 中:= ?= += =的区别
- ubuntu下Eclipse+CDT+GDB调试android NDK程序
- C++调用大数组出现栈溢出的问题解决方法,堆和栈的完全解析
- poj 1995 Raising Modulo Numbers 快速模幂
- “scanf扫描集”的初体验
- 【Python排序搜索基本算法】之冒泡排序
- github
- POJ3411--Paid Roads
- poj 3468 A Simple Problem with Integers(线段树区间更新 or 树状数组区间更新)
- UIKit 图片的移动、位移、旋转、缩放、翻转、翻页等特效的使用
- Makefile debug的经验
- TQ2440开发板open ssh移植
- 安卓的简单开发应用
- 安卓开发之意图对象篇 比如打电话 发短信