human
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"
How can the above be solved in Python?
assistant
#Here is code to sort the character array based on ASCII % N and the other steps required.
 def partition ( arr , low , high , mod ) :
	pivot = ord ( arr [ high ] ) ;
	i = ( low - 1 ) ;
	piv = pivot % mod ;
	for j in range ( low , high ) :
		a = ord ( arr [ j ] ) % mod ;
		if ( a <= piv ) :
			i += 1 ;
			arr [ i ] , arr [ j ] = arr [ j ] , arr [ i ]
	arr [ i + 1 ] , arr [ high ] = arr [ high ] , arr [ i + 1 ]
	return ( i + 1 ) ;
def quickSort ( arr , low , high , mod ) :
	if ( low < high ) :
		pi = partition ( arr , low , high , mod ) ;
		quickSort ( arr , low , pi - 1 , mod ) ;
		quickSort ( arr , pi + 1 , high , mod ) ;
		return arr
def printArray ( arr , size ) :
	for i in range ( 0 , size ) :
		print ( arr [ i ] , end = " ▁ " ) ;
if __name__ == " _ _ main _ _ " :
	arr = [ ' g ' , ' e ' , ' e ' , ' k ' , ' s ' ] ;
	n = len ( arr ) ;
	mod = 8 ;
	arr = quickSort ( arr , 0 , n - 1 , mod ) ;
	printArray ( arr , n ) ;