Como se muestra a continuación:
// ---------- Algoritmos de clasificación var sort = {} sort.prototype = {// sort con sort Systemsort: function (Array) {return Array.sort (function (a, b) {return a-b;}); }, // bubblesort: function (array) {var i = 0, len = array.length, j, d; for (; i <len; i ++) {for (j = 0; j <len; j ++) {if (array [i] <array [j]) {d = array [j]; array [j] = array [i]; matriz [i] = d; }}} matriz de retorno; }, // Quick Sort Quicksort: function (Array) {// var array = [8,4,6,2,7,9,3,5,74,5]; // matriz var = [0,1,2,44,4,324,5,65,6,6,34,4,5,6,6,43,5,6,62,43,5,1,4,51,56,76,7,7,2,1,45,4,6,6,7]; var i = 0; var j = array.length - 1; var sort = function (i, j) {// condición final if (i == j) {return}; var key = array [i]; var tempi = i; // registrar la posición de inicio var tempj = j; // Registre la posición final mientras (j> i) {// j << -----------------------------------------------------------------------------------------------------------------> Encuentre hacia atrás mientras (j> ++ i) {if (Array [i]> Key) {Array [J] = Array [i]; romper; }}}}} // Si la primera clave recuperada es el número más pequeño if (tempi == i) {sort (++ i, tempj); devolver ; } // La última vacante se deja a la matriz de clave [i] = clave; // clasificación recursiva (tempi, i); Sort (j, tempj); } Sort (i, j); matriz de devolución; }, // Insertar Sort Sorteo InsertSort: Function (Array) {// http://baike.baidu.com/image/d57e99942da24e5dd21b7080 // http://baike.baidu.com/view/396887.htm // 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,2,1,45,4,6,7]; var i = 1, j, temp, key, len = array.length; para (; i <len; i ++) {temp = j = i; clave = array [j]; while (-j> -1) {if (array [j]> key) {array [j+1] = array [j]; } else {break; }} matriz [j+1] = clave; } matriz de retorno; }, // 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]; // reverso () Consulte esta matriz óptima del tamaño de paso más pequeño VAR TEMPARR = [1031612713, 217378076, 45806244, 9651787, 2034035, 428481, 90358, 19001, 4025, 836, 182, 34, 9, 1] // Select Var I = 0 para el paso de la variedad de la varilla de la variedad I = 0 para el paso de la variedad de la variedad de la varía. 0; var temparrTemparrLength = temparr.length; var len = array.length; var len2 = parseint (len/2); for (; i <temparrLength; i ++) {if (temparr [i]> len2) {continuar; } tempsort (temparr [i]); } // Ordenar una función de paso tempsort (temp) {//console.log(temp) estadística de tamaño de paso se usa var i = 0, j = 0, f, tem, key; var templen = len%temp> 0? parseint (len/temp) + 1: len/temp; for (; i <temp; i ++) {// bucle las columnas a su vez para (j = 1;/ * j <Templen && */temp * j+i <len; j ++) {// bucle la fila de cada columna en Tem = f = Temp * j+i; clave = array [f]; while ((temp- = temp)> = 0) {// busca if (array [tem]> key) {array [tem+temp] = array [tem]; } else {break; }} array [TEM + temp] = Key; }}} matriz de retorno; }}Las diversas implementaciones de algoritmo (resumen) de JS son todo el contenido compartido por el editor. Espero que pueda darle una referencia y espero que pueda apoyar más a Wulin.com.