您的位置 首页 java

用js写冒泡排序

<!DOCTYPE html>

<html lang=”en”>

<head>

<meta charset =”UTF-8″>

<meta http-equiv=”X-UA-Compatible” content=”IE=edge”>

<meta name=”viewport” content=”width=device-width, initial-scale=1.0″>

<title>Document</title>

</head>

<body>

< script >

const arr = [5, 4, 9, 3, 2, 1];

for (let i = 0; i <= arr.length – 1; i++) {

for (j = 0; j <= arr.length – i – 1; j++) {

if (arr[j] > arr[j + 1]) {

var tmpe = arr[j]

arr[j] = arr[j + 1]

arr[j + 1] = tmpe

}

}

}

console.log(arr);

</script>

</body>

</html>

文章来源:智云一二三科技

文章标题:用js写冒泡排序

文章地址:https://www.zhihuclub.com/179098.shtml

关于作者: 智云科技

热门文章

网站地图