JS实现冒泡排序
程序员文章站
2022-03-13 15:29:11
...
JS实现冒泡排序
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>冒泡算法</title>
</head>
<body>
<script>
var arr=[6,5,1,2,4,3,8,9,7,32,44,22,53,23,25,67,64,33,76,78,33,56,45,23,22,4,12,15,14];
for (j=0;j<arr.length-1;j++){
for (i=0;i<arr.length-1;i++)
{
var temp='';
if (arr[i]>arr[i+1]){
temp=arr[i];
arr[i]=arr[i+1];
arr[i+1]=temp;
}
}
}
console.log(arr)
</script>
</body>
</html>
运行结果如下
上一篇: css Bulma框架是什么
下一篇: APT如何升级mysql