Quick Sort (Quicksort) is the Bubble Sort an improvement.
Quick Sort by C. A. R. Hoare was introduced in 1962. Its basic idea is: by a trip to sort the data will be sorted into two separate parts, one part of all the data is smaller than the other part of all the data , and then this method to the two parts of the data to be quickly sorted, the entire sorting process can be recursive To achieve an orderly sequence of the entire data.
The worst case of time complexity is O (NLOGN), a sort that is more commonly used in similar complexity
var s = [72 ,6, 57, 88, 60, 42, 83 ,73, 48,57,72, 85];quicksort (s,0, s.length-1) console.log ("----------------------------") Console.log (S.join (" ") Function quicksort (s,from,to) { if (from>=to ) { return; } //Select the starting number as the benchmark var i=from,_mid=s[i],j= to; while (I<J) { //first from the right to the left looking for a smaller while than the benchmark (s[j ]>=_MID&NBSP;&NBSP;&&&NBSP;I<J) { j--; } if (I<J) {//description found smaller than base, swap var temp=s[j]; s[j]=s[i]; s[i]=temp; i++; } // From the left to the right, looking for a larger swap position than the base while (s[i]<_mid && i <J) { i++; } if (I<J) {//description found larger than base, Exchange var temp=s[j]; s[j]=s[i]; s[i]=temp; j--; } } //program jump out of the loop here is the IJ meet and for the central point //next to the left and right order (in addition to the baseline number) quicksort (s,from,i-1); QuickSort (s,i+1,to);}
Similar to the previous bubble algorithm, and then the last sort of schematic description:
Reprint please specify the Source: http://my.oschina.net/freddon/blog/527809.
[Algorithm research]の fast sorting algorithm--javascript implementation