摘要:
二分插入排序思路先在有序区通过二分查找的方法找到移动元素的起始位置,然后通过这个起始位置将后面所有的元素后移。二分插入排序实现Function.prototype.method = function(name, func){ this.prototype[name] = func; return this;};Array.method('bInsertSort', function(){ var len = this.length, i, j, tmp, low, high, mid; for(i=1; i=high+1; j--){ ... 阅读全文
摘要:
插入排序思路从第二个元素开始和它前面的元素进行比较,如果比前面的元素小,那么前面的元素向后移动,否则就将此元素插入到相应的位置。插入排序实现Function.prototype.method = function(name, func){ this.prototype[name] = func; return this;};Array.method('insertSort', function(){ var len = this.length, i, j, tmp; for(i=1; i=0 && tmp < this[j]){ th... 阅读全文