Nodejs Utililty Methods Array Quick Sort

List of utility methods to do Array Quick Sort

Description

The list of methods to do Array Quick Sort are organized into topic(s).

Method

quickSort(comparator)
Array.prototype.quickSort = function (comparator) {
  if (typeof comparator !== "function") {
    comparator = function (x, y) {
      if (x === y) {
        return 0;
      } else if (x < y) {
        return -1;
      } else {
        return 1;
...
quickSort(start, len)
Array.prototype.quickSort = function(start, len) {
  if (typeof len === "undefined") {
    len = this.length;
  if (len < 2) {
    return this;
};
Array.prototype.swap = function (idx1, idx2) {
...
quick_sort()
Array.prototype.quick_sort = function () {
    if (this.length < 2) { return this; }
    var pivot = this[Math.round(this.length / 2)];
    return this.filter(x => x <  pivot)
               .quick_sort()
               .concat(this.filter(x => x == pivot))
               .concat(this.filter(x => x >  pivot).quick_sort());
};
quick_sort()
Array.prototype.quick_sort = function () {
    if (this.length < 2) { return this; }
    var pivot = this[Math.round(this.length / 2)];
    return this.filter(x => x < pivot)
               .quick_sort()
               .concat(this.filter(x => x === pivot))
               .concat(this.filter(x => x > pivot).quick_sort());
};
quick_sort()
Array.prototype.quick_sort = function ()
    if (this.length <= 1)
        return this;
    var pivot = this[Math.round(this.length / 2)];
    return this.filter(function (x) { return x <  pivot }).quick_sort().concat(
           this.filter(function (x) { return x == pivot })).concat(
           this.filter(function (x) { return x >  pivot }).quick_sort());
quick_sort()
Array.prototype.quick_sort = function () {
    if (this.length < 2) { return this; }
    var pivot = this[Math.floor(Math.random() * this.length)];
    return this.filter(x => x <  pivot)
               .quick_sort()
               .concat(this.filter(x => x == pivot))
               .concat(this.filter(x => x >  pivot).quick_sort());
};
qsort(array, begin, end)
function partition(array, begin, end, pivot)
  var piv=array[pivot];
  array.swap(pivot, end-1);
  var store=begin;
  var ix;
  for(ix=begin; ix<end-1; ++ix) {
    if(array[ix]<=piv) {
      array.swap(store, ix);
...
qsort(array, begin, end)
Array.prototype.swap=function(a, b)
  var tmp=this[a];
  this[a]=this[b];
  this[b]=tmp;
function partition(array, begin, end, pivot)
  var piv=array[pivot];
...
qsort(array, begin, end)
$(function ($) {
function dosort(form)
  var array=form.unsorted.value.split(/ +/);
  quick_sort(array);
  form.sorted.value=array.join(' ');
function quick_sort(array)
  qsort(array, 0, array.length);
function qsort(array, begin, end)
  if(end-1>begin) {
    var pivot=begin+Math.floor(Math.random()*(end-begin));
    pivot=partition(array, begin, end, pivot);
    qsort(array, begin, pivot);
    qsort(array, pivot+1, end);
function partition(array, begin, end, pivot)
  var piv=array[pivot];
  array.swap(pivot, end-1);
  var store=begin;
  var ix;
  for(ix=begin; ix<end-1; ++ix) {
    if(array[ix]<=piv) {
      array.swap(store, ix);
      ++store;
  array.swap(end-1, store);
  return store;
Array.prototype.swap=function(a, b)
  var tmp=this[a];
  this[a]=this[b];
  this[b]=tmp;
});
qsort(array, begin, end)
Array.prototype.swap=function swapf(a, b)
    var tmp=this[a];
    this[a]=this[b];
    this[b]=tmp;
function partition(array, begin, end, pivot)
    var piv=array[pivot];
...