Sort the character array based on ASCII % N | This function takes last element as pivot , places the pivot element at its correct position in sorted array , and places all smaller ( smaller than pivot ) to left of pivot and all greater elements to right of pivot ; pivot ; Index of smaller element ; If current element is smaller than or equal to pivot Instead of values , ASCII % m values are compared ; Increment index of smaller element ; swap ; The main function that implements QuickSort arr [ ] -- > Array to be sorted , low -- > Starting index , high -- > Ending index ; pi is partitioning index , arr [ p ] is now at right place ; Separately sort elements before partition and after partition ; Function to print the given array ; Driver code ; Sort the given array ; Print the sorted array
function partition ( arr , low , high , mod ) { var pivot = arr [ high ] ; var i = ( low - 1 ) ; var piv = pivot % mod ; for ( var j = low ; j <= high - 1 ; j ++ ) { var a = arr [ j ] % mod ; if ( a <= piv ) { i ++ ; var t = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = t ; } } var t = arr [ i + 1 ] ; arr [ i + 1 ] = arr [ high ] ; arr [ high ] = t ; return ( i + 1 ) ; } function quickSort ( arr , low , high , mod ) { if ( low < high ) { var pi = partition ( arr , low , high , mod ) ; quickSort ( arr , low , pi - 1 , mod ) ; quickSort ( arr , pi + 1 , high , mod ) ; } } function printArray ( arr , size ) { for ( var i = 0 ; i < size ; i ++ ) document . write ( arr [ i ] + " " ) ; } var arr = [ ' ' , ' ' , ' ' , ' ' , ' ' ] ; var n = arr . length ; var mod = 8 ; quickSort ( arr , 0 , n - 1 , mod ) ; printArray ( arr , n ) ;