var arr = [3, 7, 2, 4, 99, 54, 78, 33, 88];
function bubbleSort(arr) {
for (var i = 0; i < arr.length; i++) {
for (var j = i + 1; j < arr.length; j++) {
if (arr[i] > arr[j]) {
var temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
console.log("第" + i + "次排序后:" + arr);
}
return arr;
}
bubbleSort(arr);
网友评论