冒泡排序
2017-11-06 本文已影响0人
小飞侠zzr
for(var j = 1 ;j<arr.length;j++){
for(var i = 0 ;i<arr.length-j;i++){
if(arr[i]>arr[i+1]){
var temp = arr[i];
arr[i] = arr[i+1];
arr[i+1] = temp;
}
}
}
for(var j = 1 ;j<arr.length;j++){
for(var i = 0 ;i<arr.length-j;i++){
if(arr[i]>arr[i+1]){
var temp = arr[i];
arr[i] = arr[i+1];
arr[i+1] = temp;
}
}
}