Discuss / JavaScript / 冒泡排序?

冒泡排序?

Topic source

曦冶程

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

var list = document.getElementById('test-list'), ls = list.children, i, j;

for (i=0;i<ls.length;i++) { for (j=i+1;j<ls.length;j++) { if (ls[i].innerText > ls[j].innerText) { list.insertBefore(ls[j], ls[i]) } } }


  • 1

Reply