Como mostrado abaixo:
// ------------ Alguns algoritmos de classificação var sort = {} Sort.prototype = {// Classificar com Sort Systemort: function (Array) {return Array.sort (function (a, b) {return a-b;}); }, // bubblesort: function (array) {var i = 0, len = array.length, j, d; para (; i <len; i ++) {for (j = 0; j <len; j ++) {if (array [i] <array [j]) {d = array [j]; Array [j] = Array [i]; Array [i] = D; }}} retornar a matriz; }, // Classificação rápida QuickSort: function (Array) {// var Array = [8,4,6,2,7,9,3,5,74,5]; // 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,1,45,4,6,7]; var i = 0; var j = array.length - 1; var sort = function (i, j) {// condição final se (i == j) {return}; var chave = array [i]; var tempi = i; // Registrar posição inicial Var tempj = j; // Registre a posição final while (j> i) {// j << ------------------------------------------------------------------------------------------------------------------------- >> Encontre para trás enquanto (j> ++ i) {if (Array [i]> key) {array [j] = matriz [i]; quebrar; }}}}} // Se a primeira chave recuperada for o menor número se (tempi == i) {sort (++ i, tempj); retornar ; } // A última vaga é deixada para a chave de chave [i] = key; // classificação recursiva (tempi, i); Classificar (j, tempj); } Classificar (i, j); matriz de retorno; }, // Inserir Sort InsertSort: function (Array) {// http://baike.baidu.com/image/d57e99942da24e5dd21b7080 // http://baike.baidu.com/view/396887.htm/varraty/Baike.Baidu.com/View/39687.htm [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]; var i = 1, j, temp, chave, len = array.length; para (; i <len; i ++) {temp = j = i; chave = array [j]; while (-j> -1) {if (array [j]> key) {array [j+1] = array [j]; } else {break; }} array [j+1] = key; } retornar a matriz; }, // Hill Sort //jun.array.shellsort(jun.array.df(10000)); Shellsort: function (Array) {// http://zh.wikipedia.org/zh/%E5%B8%8C%E5%B0%94%E6%8E%92%E5%BA%8F // var Array = [13,14,94,33,82,25,59,94,65,23,45,27,73,25,39,10]; // var temparr = [1750, 701, 301, 132, 57, 23, 10, 4, 1]; // reverse () consulte esta matriz ideal de tamanho menor de etapa var temparr = [1031612713, 217378076, 45806244, 9651787, 2034035, 428481, 90358, 19001, 4025, 835, 182, 428481. i = 0; var temparrTemparrLength = temparr.length; var len = array.length; var len2 = parseint (len/2); para (; i <temparrLength; i ++) {if (temparr [i]> len2) {continuação; } tempsort (temparr [i]); } // classificar uma função de etapa tempsort (temp) {//console.log(temp) estatísticas de tamanho de etapa usadas var i = 0, j = 0, f, tem, chave; var Templen = Len%temp> 0? parseint (len/temp) + 1: len/temp; para (; i <temp; i ++) {// loop as colunas, por sua vez, para (j = 1;/ * j <templen && */temp * j+i <len; j ++) {// loop a linha de cada coluna em sua vez tem = f = temp * j+i; chave = array [f]; while ((tem- = temp)> = 0) {// Procure se (array [tem]> key) {array [temp+temp] = matriz [tem]; } else {break; }} Array [temp + temp] = key; }}} retornar a matriz; }}As várias implementações de algoritmo de classificação acima (resumo) de JS são todo o conteúdo compartilhado pelo editor. Espero que você possa lhe dar uma referência e espero que você possa apoiar mais o wulin.com.