Javascript Array quickSort(start, len)

Description

Javascript Array quickSort(start, len)


// Incomplete//w  w  w.ja v a2 s  . co m

Array.prototype.quickSort = function(start, len) {
  if (typeof len === "undefined") {
    len = this.length;
  }
  if (len < 2) {
    return this;
  }

};

Array.prototype.swap = function (idx1, idx2) {
  var temp = this[idx1];
  this[idx1] = this[idx2];
  this[idx2] = temp;
};

Javascript Array quicksort(start, len)

Array.prototype.quicksort = function (start, len) {
  if (len <= 1) return this;

  var length = len || this.length;
  var startIdx = start || 0;
  var pivotIdx = this.partition(startIdx, len);

  this.quicksort(startIdx, pivotIdx - startIdx);
  this.quicksort(pivotIdx + 1, len - (pivotIdx + 1));

  return this;/*from   www.j  a  v a  2s  . c o  m*/
};



PreviousNext

Related