Nodejs Array Shell Sort shellSort()

Here you can find the source of shellSort()

Method Source Code

Array.prototype.shellSort= function() {
   var j, gap; /*w w  w  .  j  av  a  2s. c  om*/
   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;  
                while (k >= 0 && this[k] > temp)  
                {  
                    this[k + gap] = this[k];  
                    k -= gap;  
                }  
                this[k + gap] = temp;  
            }  
}

var b = [123,25,67,25,137,225,24,467];
b.shellSort(3);
console.log(b);

Related

  1. shellSort()
    Array.prototype.shellSort = function () {
      var gap, i, j;
      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;
    };
    
  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;
    };