向Array中添加冒泡排序
2013-10-09 13:10
162 查看
冒泡排序思想
通过在无序区的相邻元素的比较和替换,使较小的元素浮到最上面。冒泡排序实现
Function.prototype.method = function(name, func){ this.prototype[name] = func; return this; }; Array.method('bubbleSort', function(){ var len = this.lenght, i, j, tmp; for(i=0; i<len; i++){ for(j=len-1; j>i; j--){ if(this[j] > this[j-1]){ tmp = this[j-1]; this[j-1] = this[j]; this[j] = tmp; } } } return this; });
相关文章推荐
- 向Array中添加改进的冒泡排序
- 向Array中添加快速排序
- JSONObject与JSONArray的使用3--Java对象属性的添加或删除(JsonConfig)
- 如何解决在快速向jtable添加数据的时候报AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException:异常
- Javascrip-js操作数组-Array-添加-修改数组-charje的博客
- 向Array中添加选择排序
- php通过array_unshift函数添加多个变量到数组前端的方法
- [Javascript]给Javascript中的Array添加Remove方法
- Objective-C - NSMutableArray添加NSInteger元素
- array_push()添加数组
- WCF Test Client 中如何为添加array 类型参数
- C#实现Array添加扩展实例
- 如何添加CGRect, CGPoint等到NSMutableArray
- js如何往数组Array中添加删除元素
- [黑马程序员一]:动态向数组中添加数据之Array,ArrayList,List,Dictionary用法
- delphi dynamic Array 排序 快速排序,选择排序,冒泡排序
- 给js添加 in_array 方法
- listview 添加 多种layout时,会出现ArrayIndexOutOfBoundsException
- 冒泡排序改进版--添加标示排序法
- JS扩展Array,添加contains方法