var arr = [23,34,3,4,23,44,333,444];冒泡排序
时间: 2023-10-06 16:04:07 浏览: 61
用冒泡排序这一算法排序数组
var arr = [23,34,3,4,23,44,333,444];
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(arr); // [3, 4, 23, 23, 34, 44, 333, 444]
阅读全文