function BubbleSort(arr){ var len = arr.length for(var i =0;iarr[j+1]){ var temp = arr[j] arr[j]=arr[j+1] arr[j+1]=temp } } } return arr}var arr = [1,3,5,7,2,4,6,8]console.log(BubbleSort(arr)) //[1,2,3,4,5,6,7,8]
本文共 316 字,大约阅读时间需要 1 分钟。
function BubbleSort(arr){ var len = arr.length for(var i =0;iarr[j+1]){ var temp = arr[j] arr[j]=arr[j+1] arr[j+1]=temp } } } return arr}var arr = [1,3,5,7,2,4,6,8]console.log(BubbleSort(arr)) //[1,2,3,4,5,6,7,8]
转载于:https://www.cnblogs.com/xpcool/p/10364412.html