Nodejs Array Insertion Sort insertationSort()

Here you can find the source of insertationSort()

Method Source Code

Array.prototype.insertationSort = function() {
    this.procedures=[]//from  ww  w  .jav a2  s.c o  m
    var compare = 0
    var exchange = 0
    var comparet = this.length * this.length / 4
    var exchanget = comparet
    for (var i = 1; i < this.length; i++) {
        for (var j = i; j > 0; j--) {
            compare++
            if (this.less(j, j - 1)) {
                this.exch(j, j - 1)
                exchange++
            } else {
                break
            }
        }
        // virtualize(this, i)
    }
}

Related

  1. insertSort()
    Array.prototype.insertSort = function () {
        'use strict';
        var lastIndex = this.length,
            temp,
            i,
            j;
        for ( i = 1 ; i < lastIndex ; i++ ) {
            for( j = 0 ; j < i ; j++ ){
                if( this[i] < this[j] ){
    ...
    
  2. insertSort()
    Array.prototype.insertSort = function() {
      for(var i = 1; i < this.length; i++) {
        var temp = this[i];
        var inp = i;
        while(inp > 0 && temp < this[inp - 1]){
          this[inp] = this[inp - 1];
          inp--;
        this[inp] = temp;
    ...
    
  3. insertSort()
    Array.prototype.insertSort=function(){
           var left=[];
          var res=this.splice(0,1)[0];
        left.push(res);
        for(var i=0;i<this.length;i++){
              var cur=this[i];
            for(var j=left.length-1;j>=0;){
                 if(left[j]>cur){
                     j--;
    ...
    
  4. insertSort()
    Array.prototype.insertSort = function(){
      var len = this.length;
      var temp;
      for(var i = 1;i < len;i++){
        temp = this[i];
        if(this[i] < this[i-1]){
          for(var j = i-1;j > 0&&temp<this[j];j--){
            this[j+1] = this[j];
          this[j+1] = temp;
      return this;
    
  5. insertion(arr)
    Array.prototype.insertion = function(arr){
        var returnArr = [];
        for(var i = 0; i < arr.length; i++){
            if(i==0){
                returnArr.push(arr[i]);
            }else{
                if(arr[i]<returnArr[i-1]){
                    var j = i;
                    while(j!=0&&arr[i]<returnArr[j]){
    ...
    
  6. insertionSort()
    Array.prototype.insertionSort = function () {
      var i, j;
      var temp;
      for (i = 1; i < this.length; i++) {
        temp = this[i];
        for (j = i - 1; j >=0 && this[j] > temp; j--) {
          this[j + 1] = this[j];
        this[j + 1] = temp;
    ...
    
  7. insertionSort()
    Array.prototype.insertionSort = function() {
      for(var i = 1; i < this.length; i++) {
        var hole = i;
        while (hole > 0 && this[hole - 1] > this[i]) {
          hole--;
        this.splice(hole, 0, this[i]);
        this.splice(i + 1, 1);
      return this;
    
  8. insertionSort()
    'use strict';
    const ArraySorting = {};
    ArraySorting.insertionSort = a => {
        for(let o = 1; o < a.length; o++) {
            for(let i = o; i > 0 && a[i] < a[i-1]; i--) {
                [a[i], a[i-1]] = [a[i-1], a[i]]
    Array.prototype.insertionSort = function () {
        ArraySorting.insertionSort(this);
    exports.ArraySorting = ArraySorting;