Here you can find the source of 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()/*w w w . j a v a 2s . c om*/ .concat(this.filter(x => x === pivot)) .concat(this.filter(x => x > pivot).quick_sort()); };
Array.prototype.quickSort = function() if (this.length === 0) { return []; var left = []; var right = []; var pivot = this[0]; for (var i = 1; i < this.length; i++) { ...
Array.prototype.quickSort = function () { if (this.length <= 1) { return this; var pointIndex = Math.floor(this.length / 2); var pointValue = this.splice(pointIndex, 1); var centerValue = pointValue[0]; var left = []; var right = []; ...
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; ...
Array.prototype.quickSort = function(start, len) { if (typeof len === "undefined") { len = this.length; if (len < 2) { return this; }; Array.prototype.swap = function (idx1, idx2) { ...
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()); };
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());
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()); };
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); ...
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]; ...