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
def partition ( arr , low , high , mod ) : NEW_LINE INDENT pivot = ord ( arr [ high ] ) ; NEW_LINE i = ( low - 1 ) ; NEW_LINE piv = pivot % mod ; NEW_LINE for j in range ( low , high ) : NEW_LINE INDENT a = ord ( arr [ j ] ) % mod ; NEW_LINE if ( a <= piv ) : NEW_LINE INDENT i += 1 ; NEW_LINE arr [ i ] , arr [ j ] = arr [ j ] , arr [ i ] NEW_LINE DEDENT DEDENT arr [ i + 1 ] , arr [ high ] = arr [ high ] , arr [ i + 1 ] NEW_LINE return ( i + 1 ) ; NEW_LINE DEDENT def quickSort ( arr , low , high , mod ) : NEW_LINE INDENT if ( low < high ) : NEW_LINE INDENT pi = partition ( arr , low , high , mod ) ; NEW_LINE quickSort ( arr , low , pi - 1 , mod ) ; NEW_LINE quickSort ( arr , pi + 1 , high , mod ) ; NEW_LINE return arr NEW_LINE DEDENT DEDENT def printArray ( arr , size ) : NEW_LINE INDENT for i in range ( 0 , size ) : NEW_LINE INDENT print ( arr [ i ] , end = " ▁ " ) ; NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ ' g ' , ' e ' , ' e ' , ' k ' , ' s ' ] ; NEW_LINE n = len ( arr ) ; NEW_LINE mod = 8 ; NEW_LINE arr = quickSort ( arr , 0 , n - 1 , mod ) ; NEW_LINE printArray ( arr , n ) ; NEW_LINE DEDENT