Beispiel für Blasenart, bidirektionale Blasensortierung mit einer leicht verbesserten Visualisierung der bidirektionalen Blasensorte.
Der Code ist sehr einfach, ich weiß nicht, ob es unbekannte Fehler gibt.
Gott, bitte beschweren Sie sich nicht
Bubble -Sortierbeispiel
var ls = [ 98,13,6,25,38,36,30,44,38,80,61,28,47,34,95,18,85,58,89,85,42,61,74,35,1 3,14,80,7,10,44,10,47,13,11,52,25,24,48,34,12,88,80,33,80,45,64,52,79,77 ]; für (var i = 0; i <lsgth; i ++) {für (var j = i+1; j <lsgth; ls [j] = ls [i] -ls [j]; ls [i] = ls [i] -ls [j]; }}}Beispiele für eine Zwei-Wege-Blasensortierung
var ls = [ 6,13,98,25,38,36,30,44,38,80,61,28,47,34,95,18,85,58,89,85,42,61,74,35,1 3,14,80,7,10,44,10,47,13,11,52,25,24,48,34,12,88,80,33,80,45,64,52,79,77 ]; für (var i = 0; i <lsgth; i ++) {für (var j = i+1; j <lsgth-i; j ++) {if (ls [lent-1-i] <ls [lent-j]) {ls [lent-1-i] ls [lent-j] = ls [lent-1-i] -ls [lent-J]; ls [lent-1-i] = ls [lent-1-i] -ls [Lent-J]; ls [lent-1-i] = ls [lent-1-i] -ls [Lent-J]; } // Der folgende Vergleich if (ls [i]> ls [j]) {ls [i] = ls [i]+ls [j]; ls [j] = ls [i] -ls [j]; ls [i] = ls [i] -ls [j]; } // Der vorherige Vergleich}}Beispiel für eine leicht verbesserte bidirektionale Blasensorte
var ls = [ 98,13,6,25,38,36,30,44,38,80,61,28,47,34,95,18,85,58,89,85,42,61,74,35,1 3,14,80,7,10,44,10,47,13,11,52,25,24,48,34,12,88,80,33,80,45,64,52,79,77 ]; var lent = lsgth; ls [j+1] = ls [i*2] -ls [j+1]; ls [i*2] = ls [i*2] -ls [j+1]; ls [i*2] = ls [i*2] -ls [j+1]; } // die erste Zahl in der inneren Schicht als minimale Schleife beibehalten (ls [lent-i*2-1] <ls [lent-j-1]) {ls [lent-i*2-1] = ls [lent-i*2-1]+ls [lent-J-1]; ls [lent-j-1] = ls [lent-i*2-1] -ls [lent-J-1]; LS [Fastenzeit-I*2-1] = ls [Fastenzeit-J-1]; } //// Die vorletzte Anzahl der inneren Schicht auf den maximalen Zyklus if (ls [lent-2-i*2] <ls [lent-j-1]) {ls [lent-2-i*2] = ls [lent-2-i*2]+ls [Lent-J-1]; LS [LENT-J-1] = LS [LENT-2-I*2] -LS [LENT-J-1]; LS [LENT-2-I*2] = LS [LENT-J-1]; LS [LENT-2-I*2] = LS [LENT-J-1]; LS [LENT-2-I*2] = LS [LENT-J-1]; } // revisieren Sie das letzte if (ls [i*2+1]> ls [j+1]) {ls [i*2+1] = ls [i*2+1]+ls [j+1]; ls [j+1] = ls [i*2+1] -ls [j+1]; ls [i*2+1] = ls [i*2+1] -ls [j+1]; }//Nächste}}