javascript数组排序汇总_javascript技巧
程序员文章站
2022-04-27 14:29:30
...
javascript数组排序汇总
//排序算法 window.onload = function(){ var array = [0,1,2,44,4, 324,5,65,6,6, 34,4,5,6,2, 43,5,6,62,43, 5,1,4,51,56, 76,7,7,2,1, 45,4,6,7,8]; //var array = [4,2,5,1,0,3]; console.log('原始数组'); console.log(array); array = sorting.shellSort(array); // alert(array); console.log('排序后的数组') console.log(array); } var sorting = { //利用sort方法进行排序 systemSort: function(arr){ return arr.sort(function(a,b){ return a-b; }); }, //冒泡排序 bubbleSort: function(arr){ var len=arr.length, tmp; for(var i=0;iarr[j+1]){ tmp = arr[j]; arr[j] = arr[j+1]; arr[j+1] = tmp; } } } return arr; }, //快速排序 quickSort: function(arr){ var low=0, high=arr.length-1; sort(low,high); function sort(low, high){ if(low =tmp){ high--; } arr[low] = arr[high]; while(low =0;j--){ if(tmp =1;h=Math.floor(h/3)){ for(var k=0;k =h&&arr[j]
以上所述就是本文的全部内容了,希望大家能够喜欢。