冒泡排序JavaScript
2021年6月7日
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>冒泡排序</title>
</head>
<body>
<script type="text/javascript">
var arr = [2,4,5,1,15,18,4,46,51,2];
//alert(arr.length);
for (var i=0;i<arr.length;i++) {
for (var j=0;j<arr.length-i-1;j++){
if(arr[j]>arr[j+1]){
var temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
alert(arr);
</script>
</body>
</html>