JS编程题冒泡排序
作者:互联网
代码实现
//冒泡排序
function bubble(arr){
for(var j=0;j<arr.length-1;j++)
{
for(var i=0;i<arr.length-1;i++)
{
if(arr[i]>arr[i+1])
{
temp=arr[i+1]
arr[i+1]=arr[i]
arr[i]=temp
}
}
}
return arr
}
var number=[10,20,5,0,7,6]
console.log("number:"+number)
console.log("bubble:"+bubble(number))
输出
标签:arr,log,temp,编程,number,冒泡排序,JS,bubble 来源: https://blog.csdn.net/m0_58138734/article/details/122658056