冒泡排序

76 阅读1分钟
const arr=[1,5,7,4,8,44,78,22]
for(let i=0;i<arr.length-1;i++){
 for(let j=0;j<arr.length-i-1;j++){
     if(arr[j]>arr[j+1]){
     let temp
     temp=arr[j]
     arr[j]=arr[j+1]
     arr[j+1]=temp
     }
 }
}
console.log(arr)