//Quick Sort functionQSort (L, Low, high) {varpivot; while(low<High ) {Pivot= Partition (L, Low, high);//divides l into dividedQSort (L, Low, pivot-1); Low= pivot + 1;//reduce stack depth with iterative rather than recursive methods to improve overall performance! } } functionswap (L, L, h) {vartemp =L[h]; L[H]=L[l]; L[L]=temp; } functionPartition (L, Low, high) {//the three-digit optimization algorithm prevents the minimum value from being too large or too small varpivotkey,temp; varm = low + (high-low)/2; M=Math.floor (m); if(L[low] >L[high]) {Swap (L, low, high); } if(L[m] >L[high]) swap (L, M, high); if(l[m]>L[low]) swap (L, Low, M); PivotKey=L[low]; Temp=PivotKey; while(Low <High ) { while(Low//Find the subscript of a value smaller than PivotKey and assign the current value to L[low]high--; } L[low]=L[high]; while(lowPivotKey) { Low++; } L[high]=L[low]; } L[low]=temp; returnLow ; } varA = [1, 4, 2, 5, 7, 8, 9, 0, 3, 2]; //Meresort (l); //MergeSort2 (l);QSort (A, 0, a.length-1); Console.log (a);
Quick sort JavaScript implementation