<!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 shellsort(arr) { interval = parseInt(arr.length / 2); while(interval > 0){ for(var i = 0;i <= arr.length ; i++){ var n = i; while(arr[n] < arr[n - interval] && n - 1 >0){ var temp = arr[n]; arr[n] = arr[n - interval]; arr[n - interval] = temp; n -= interval; } } interval = parseInt(interval / 2); } return arr; } console.log(shellsort(arr)); </script> </body> </html>
希尔排序
最新推荐文章于 2024-08-16 10:24:49 发布