冒泡算法
var array = [10,20,1,2,100,6];
//
for (var i = 0 ; i < array.length-1; i++)
{
for (var j = 0 ; j < array.length-1-i; j++){
if (array[j]<array[j+1]){
var tmp = array[j];
array[j] = array[j+1];
array[j+1] = tmp;
}
}
}
console.log(array);
alert(array);
网友评论