The idea of "quick sorting" is simple, and the entire sequencing process takes only three steps:
(1) In the dataset, select an element as the "datum" (pivot).
(2) All elements smaller than "datum" are moved to the left of "datum", and all elements that are greater than "datum" are moved to the right of "datum".
(3) for the two subsets to the left and right of the Datum, repeat the first and second steps until there is only one element left in all the subsets.
var function quickSort (arr) {
if (arr.length<=0) {
return arr;
}
var pivotindex = Math.floor (ARR.LENGTH/2);
var pivot = Arr.splice (pivotindex, 1) [0];
var left = [];
var right = [];
for (var i = 0; i < arr.length; i++) {
if (Arr[i] < pivot) {
Left.push (Arr[i]);
} else {
Right.push (Arr[i]);
}
}
Return QuickSort (left). Concat ([pivot], QuickSort (right));//use recursion to repeat the process, you can get the sorted array.
}
JavaScript Quick Sort Method