Javascript Array createHeap(low, high)

Description

Javascript Array createHeap(low, high)


Array.prototype.createHeap = function(low, high){
 var i = low, j = 2 * i, tmp = this[i];
 while(j <= high){
  if(j < high && this[j] < this[j+1])
   j++;/*  ww  w.j  a va2s. c om*/
  if(tmp < this[j]){
   this[i] = this[j];
   i = j;
   j = 2 * i;
  }else break;
 }
 this[i] = tmp;
 return this;
}



PreviousNext

Related