JavaScript丨冒泡排序(大->小 )

 

冒泡排序:

var arr = [100, 3, 20, 200, 60, 888, 0]
console.log('arr1===', arr)

for (var i = 0; i < arr.length - 1; i++) {
    for (var j = 0; j < arr.length - 1 - i; j++) {
        if (arr[j] < arr[j + 1]) {
            var temp = arr[j]
            arr[j] = arr[j + 1]
            arr[j + 1] = temp
        }
    }
}

console.log('arr2====', arr)

 

 

参考:

https://github.com/wangjianuo/blog/issues/2

 

posted @ 2019-06-16 22:45  wangjianuo  阅读(1059)  评论(0编辑  收藏  举报