标签:else 排序 false for function javascrip java type pre
<script type="text/javascript">
function bubbleSort(ary) {
for(var i =0;i<ary.length-1;i++){
var flag = false;
for(var j = 0;j<ary.length-1-i;j++){
if(ary[j]>ary[j+1]){
ary[j]=ary[j]+ary[j+1];
ary[j+1]=ary[j]-ary[j+1];
ary[j] =ary[j]-ary[j+1];
flag = true;
}
}
if(flag){
flag =false;
}else {
break;
}
}
return ary;
}
var arr=[2,51,3,1,7,8,78,89];
console.log(bubbleSort(arr));
</script>
标签:else 排序 false for function javascrip java type pre
原文地址:http://www.cnblogs.com/zzzzzzzsy/p/6486393.html