Nodejs Array Shell Sort shellSort()

Here you can find the source of shellSort()

Method Source Code

Array.prototype.shellSort = function () {
  var gap, i, j;/*from w  w  w  .j  av  a  2  s .  c  o  m*/
  var temp;
  for (gap = this.length >> 1; gap > 0; gap >>= 1) {
    for (i = gap; i < this.length; i++) {
      temp = this[i];
      for (j = i - gap; j >= 0 && this[j] > temp; j -= gap) {
        this[j + gap] = this[j];
      }
      this[j + gap] = temp;
    }
  }
};

Related

  1. shellSort()
    Array.prototype.shellSort= function() {
      var j, gap; 
      var n = this.length; 
        for (gap = n / 2; gap > 0; gap /= 2)  
            for (j = gap; j < n; j++)
                if (this[j] < this[j - gap])
                    var temp = this[j];  
                    var k = j - gap;  
    ...
    
  2. shellSort()
    Array.prototype.shellSort = function(){
      var temp,len = this.length;
      for(var increment = Math.floor(len/2);increment > 0;increment = Math.floor(increment/2)){
        for(var i = increment;i < len;i++){
          for(var j = i - increment;j >= 0&&this[j] > this[j + increment];j -= increment){
            temp = this[j];
            this[j] = this[j+increment];
            this[j+increment] = temp;
      return this;
    
  3. shellSort()
    Array.prototype.shellSort = function() {
        this.procedures = []
        var l = this.length
        var compare = 0
        var exchange = 0
        var comparet = Math.sqrt(l * l * l)
        var exchanget = '?'
        var list = [0, 1, 5, 19, 41, 109, 209, 505, 929, 2161, 3905, 8929, 16001, 36289, 64769, 146305, 260609]
        var listnum = 1
    ...
    
  4. shellSort()
    Array.prototype.shellSort = function () {
        for (var step = parseInt(this.length)/2; step > 0; step--) {
            for(var i = 0; i < step; i++) {
                for (var j = step+i; j < this.length; j += step) {
                    var k = j, value = this[k];
                    while(k >= step && value < this[k-step]){
                        this[k] = this[k-step];
                        k -= step;
                    this[k] = value;
    };
    
  5. shellSort2()
    Array.prototype.shellSort2 = function() {
        var l = this.length
        var compare = 0
        var exchange = 0
        var comparet = Math.sqrt(l * l * l)
        var exchanget = '?'
        var h = 128
        while (h < l / 2) h = 2 * h + 1
        while (h >= 1) {
    ...