arr =[134,124,45,769,4356,3,8]
function bubble(arr){
for(i=0;i<=arr.length-1;i++){
//每轮比较次数少1
for(j=0;j<=arr.length-1-i;j++){
if(arr[j]>arr[j+1]){
let temp = arr[j+1];
arr[j+1]=arr[j];
arr[j]= temp;
}
}
}
return arr;
}
网友评论