First, the concept of rapid sorting method
We have a messy array for a quick sort, you can first from an array to take an intermediate value, an array is divided into 2, the left of the array with the median comparison, small on the left side, large on the right. After the comparison is finished again to take the median, again compare the analogy two, thinking 1, take the median, and the intermediate value of the subscript 2, create a left empty array, store less than the median value of data 3, create a right empty array, storage greater than the median value of data 4, recursive termination conditions, if the length of the array is equal to 1 Returns an array of 5, loops the array into 26, recursively
Third, the Code
functionquicksort (arr) {if(arr.length<2){ returnarr; } varMidindex = arr.length%2 = = 0? ARR.LENGTH/2: (arr.length+1)/2; varMID =Arr[midindex]; varleft = []; varright = []; for(vari=0;i<arr.length;i++){ if(I! = Midindex && Arr[i] <=mid) {Left.push (arr[i]); } if(I! = Midindex && Arr[i] >mid) {Right.push (Arr[i])}} returnquicksort (left). Concat (mid). Concat (quicksort)}
"JavaScript algorithm"---fast sorting method