首页 > 代码库 > js 冒泡排序

js 冒泡排序

<!DOCTYPE html>
<html lang="en">
<head>
<script type="text/javascript">
var arr=[17,19,5,90,3];
window.onload=function(){

// alert(arr[0])
/var len=arr.length;
// alert(len);
for(var i=0;i<len;i++){

for( var j=i+1; j<len; j++){

if(arr[i]>arr[j]){

var temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
document.write(arr[i]);
document.write(",");
}
}
</script>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    
</body>
</html>

js 冒泡排序