<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>插入排序</title> </head> <body> <script> var arr = [6,3,5,12,44,4,9,8,7,1]; function charusort(arr) { for(var i = 1; i < arr.length; i++){ for(var j = i; j > 0; j--){ if(arr[j] < arr[j - 1]){ var temp = arr[j - 1]; arr[j - 1] = arr[j]; arr[j] = temp; } } if(i == arr.length - 1){ list = arr; } } return list; } console.log(charusort(arr)); </script> </body> </html>
插入排序
最新推荐文章于 2024-08-16 22:18:58 发布