Fast sorting algorithm, is my algorithm series blog in the second JS implementation of the algorithm, the main idea: a random number in an array (generally take the first or last), so that the number and the other number in the array to compare, if larger than it to the right side, It is smaller than it is to the left of the number, recursively call until the comparison queue only two numbers.
Code implementation:
varArrs = [23,85,61,37,55,12,63,11,99,39,70,21,23];functionQuickSort (arr, s,e) {varLen =e; vartoken =Arr[s]; for(vari=s+1;i<=len;i++){ varTTT =Arr[i]; if(Token >=Arr[i]) { vartemp =Arr[i]; for(varK = i;k>s;k--) {Arr[k]= Arr[k-1]; } Arr[s]=temp; S++; } } returns;}functionSort (arrs,s,e) {vart =QuickSort (arrs,s,e); if(T-1 >=s) {Sort (arrs, s,t-1); } if(T+1 <=e) {sort (arrs, T+1, E); }} sort (Arrs,0, Arrs.length);d Ocument.getelementbyid ("App"). InnerHTML = arrs+ "";
Note: The code may also have a place to optimize, welcome to The Spit Groove!
Quick ordering of structure-behavior-style-js sorting algorithm