1 回答
TA贡献1875条经验 获得超3个赞
先说下,我也是新手,所以第一次回答的有些问题,有错的地方还请海涵;
下面是我改的,不足之处,不吝赐教;
var lii = document.getElementsByTagName('li');
var liiLength = lii.length;
var liiArr = [];
//I think
for(var i=0;i<liiLength;i++){
liiArr.push( parseInt(lii[i].innerText) );
}
function bubbleSort(lii){
var li = lii;
var temp = '';
for(var i = 0; i < li.length-1; i++){
for(var j = 0;j < li.length-i-1;j++){
if(li[j] > li[j+1] ){
//I think
temp = li[j];
li[j] = li[j+1];
li[j+1] = temp;
}
}
}
return li;
}
function ff(lii){
var aa = bubbleSort(lii);
var aaLength = aa.length;
for(var i = 0; i < aaLength; i++){
document.write( aa[i] );
}
}
ff(liiArr);
添加回答
举报