算法笔记(1) ——插入算法

var ary = [5, 2, 4, 6, 1, 3,31,4,0,1,43];
function InsertionSort(){
for (var j = 1; j < ary.length; j++) {
var key = ary[j];
var i = j - 1;

while(i >= 0 && ary[i] > key){
ary[i + 1] = ary[i];
i--;
}
ary[i + 1] = key;
};
}
posted @ 2012-03-17 19:58  Miser  阅读(213)  评论(0编辑  收藏  举报