标签:iss class order ble 改进 strong 标记 冒泡 ons
// 冒泡排序算法 function bubbleSort(arr) { console.log(‘排序算法第0次:‘ + arr.join(‘,‘)); var len = arr.length; var lastIndex = 0; // 最后标记的脚标 var sortBorder = len - 1; // 需交换最大的次数 for (var i = 0; i < len - 1; i++) { let isSort = true; for (var j = 0; j < sortBorder; j++) { if (arr[j] > arr[j + 1]) { var temp = arr[j + 1]; arr[j + 1] = arr[j]; arr[j] = temp; lastIndex = j; isSort = false; } } sortBorder = lastIndex; if (isSort) { break; } console.log(‘排序算法第‘ + (i + 1) + ‘次:‘ + arr.join(‘,‘)); } return arr; }
var array = [3, 4, 1, 2, 5, 6, 7, 8];
bubbleSort(array);
标签:iss class order ble 改进 strong 标记 冒泡 ons
原文地址:https://www.cnblogs.com/peter-web/p/12550130.html