Sort Algorithm-->Bubble Sort
2016-07-24 20:16
483 查看
Bubble sort:
Everytime index start from left,compare two elements,if left element bigger then right element,than swap them, or index move to next. After a traverse, the max element of the rest will float to the right of n,n-1,n-2’s position like bubbles.Complexity:O(n^2)
""" bubble sort language:python3.5 author:zhoutonglx """ #original unsorted list L = [3,44,38,5,47,15,36,26,27,2,46,4,19,50,48] def BubbleSort(L): length = len(L) for i in range(length-1) : for j in range(length-i-1) : if L[j]>L[j+1] : L[j],L[j+1] = L[j+1],L[j] # like swap() in c++ print(L) if __name__ == "__main__" : BubbleSort(L)
相关文章推荐
- Google首席工程师Joshua Bloch谈如何设计优秀的API
- Algorithms for Detecting Significantly Mutated Pathways in Cancer
- Google推荐的图片加载库Glide介绍
- 使用google的zxing类生成一维码、二维码实例
- ”The virtual device got no IP address.“的解决
- hdu 5190 Go to movies(水)
- Django中CSRF实现分析
- 维特比算法(Viterbi Algorithm)
- 前向算法(Forward Algorithm)
- golang的参数验证
- django 静态文件路径设置
- MyBatis Generator 详解(good)
- hiho108周即题库1198Memory Allocating Algorithm
- 卡方检验(Chi-square test/Chi-Square Goodness-of-Fit Test)
- Django博客开发(十三)—一个简单的站内搜索
- L11,one good turn deserves another
- POJ3623 Best Cow Line,Gold
- 1.go开源groupcache项目——groupcache介绍
- Google百分比布局支持库----让屏幕适配更简单
- 21世纪的领导力