Nodejs Array Heap Sort heapSort()

Here you can find the source of heapSort()

Method Source Code

//heap sort time complexity is O(n(log n)) and space complexity is O(1)
Array.prototype.heapSort = function() {
  if (this.length < 2) {
    return this;/*from   w w  w .  ja  v  a2  s  . c o  m*/
  } else {
    this.heapify();
    this.unheapify();
    return this;
  }
}

Related

  1. heapSort()
    ;"use strict";
    var log=function(msg){console.log(msg);};
    var alert=function(msg){log(msg);};
    var arr = [3,6,7,5,3,6,2,9,1,5,33,-12,0,-122,-Infinity, 125, 33, 55, 77];
    Array.prototype.heapSort = function () {
      arr = this;
      function _chunk(list) {
        var chunks = [];  
        for(var i=0; i<list.length; i++) {
    ...
    
  2. heapSort()
    Array.prototype.heapSort = function() {
      var unsortedArray = this;
      class BinaryHeap {
        constructor() {
          this.content = [];
        push(elementToAdd) {
          this.content.push(elementToAdd);
          this.bubbleUp(this.content.length - 1);
    ...