var arr = [23, 3, 24, 67, 21, 60];
1 冒泡排序
for (let j = arr.length - 1; j > 0; j--) {
for (let i = 0; i < j; i++) {
if (arr[i] > arr[i + 1]) {
let temp = arr[i];
arr[i] = arr[i + 1];
arr[i + 1] = temp
}
}
console.log('第'+j+'次循环',arr);
}
2 选择排序
for (let j = 0; j<arr.length; j++){
for (let i = 0; i < arr.length; i++) {
if(arr[i] > arr[j]){
let temp = arr[i];
arr[i] = arr[j]
arr[j] = temp
}
}
console.log('第'+(j+1)+'次循环',arr);
}