The time complexity of fast sorting is: O (n*log2n), compared with other O (N2) sorting algorithm, or more advantageous. The original reference is here, because I am a little bit of code in the original text is not understood, so made a small change.
1. Basic idea: Select one in the first or last element of the array, as the datum element, also called the middle axis. By sorting, let the middle axis divide the array into two parts, some smaller than the middle axis, and a part larger. Then the same sort of two parts are sorted by recursive method.
2. Example:
3.js Code
varArrayquick = [7,9,4,8,2,24,54,12,32,11,2];quick (Arrayquick,0,ARRAYQUICK.LENGTH-1);//The latter two parameters determine the quick ordering of a certain part of the array,functionQuick (List,low,high) {if(low<High ) { varMiddle = getmiddle (List,low,high);//divides a list array into a splitQuick (list,low,middle-1);//recursive ordering of low-word tablesQuick (List,middle+1,high);//recursive ordering of high-character tables }}functionGetmiddle (list,low,high) {varTMP = List[low];//the first of the array is a datum element, that is, the middle axis while(low<High ) { while(low//looking for lower-than-mid-axis data from high-end to mid-axis{ High--; } //find lower-than-mid-axis data at high end, then swap locationslist[low]=List[high]; List[high]=tmp; while(low//looking for data higher than the middle axis from the low-side to the middle axis{ Low++; } //find data at the lower end that is higher than the middle axis, and then swap positionslist[high]=List[low]; List[low]=tmp; } returnLow//returns the position of the middle axis} for(vari=0; i<arrayquick.length; i++) {Cc.log (arrayquick[i]);}