<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> </head> <body> <button οnclick="commit()">确定</button> </body> <script> function commit() { var arr = [1,4,8,9,6,3] var min = 0 var j = 0 for (var i = 0;i <arr.length; i++) { // for ( j = i + 1 ; j < arr.length; j++ ) { // if (arr[i] > arr[j]) { // min = arr[j]; // arr[j]=arr[i]; // arr[i]=min; // // } // // } for ( j = 0 ; j < arr.length-i-1; j++ ) { if (arr[j] > arr[j + 1]) { min = arr[j]; arr[j]=arr[j+1]; arr[j+1]=min; } } } console.log(arr) } </script> </html>
【学习】从小到大数组排序
最新推荐文章于 2022-07-27 18:34:24 发布