Javascript Array quickSort(s,t)

Description

Javascript Array quickSort(s,t)


Array.prototype.quickSort = function(s,t){
 var i = s, j = t, tmp;
 if(s < t){/*w  w w .  j av  a 2s . c o m*/
  tmp = this[s];
  while(i != j){
   while(j > i && this[j] > tmp){
    j--;
   }
   this[i] = this[j];
   while(i < j && this[i] < tmp){
    i++;
   }
   this[j] = this[i];
  }
  this[i] = tmp;
  this.quickSort(s, i-1);
  this.quickSort(i+1, t);
 }
 return this;
}



var arr = [14, 6, 9, 4, 11];
var nArr = arr.quickSort(0,4);
console.log(nArr);



PreviousNext

Related