Discuss / JavaScript / 随便写一个冒泡排序

随便写一个冒泡排序

Topic source

xiaolureve

#1 Created at ... [Delete] [Delete and Lock User]

var list = document.getElementById('test-list');

for(let i = 0 ; i < list.children.length - 1 ; ++i){

    for(let j = 0 ; j < list.children.length-i-1 ; ++j){

        if(list.children[j].innerText > list.children[j + 1].innerText){

            list.insertBefore(list.children[j + 1], list.children[j]);

        }

    }

}


  • 1

Reply