human
Insertion sort to sort even and odd positioned elements in different orders | Function to calculate the given problem ..
checking for odd positioned ..
Inserting even positioned elements in ascending order ..
sorting the even positioned ..
Inserting odd positioned elements in descending order ..
A utility function to print an array of size n.
Driver program"
How can the above be solved in Python?
 Give me a code to insertion sort to sort even and odd positioned elements in different orders and the other steps required?
assistant
#Here is code to insertion sort to sort even and odd positioned elements in different orders and the other steps required.
 def evenOddInsertionSort ( arr , n ) :
	for i in range ( 2 , n ) :
		j = i - 2
		temp = arr [ i ]
		if ( ( i + 1 ) & 1 == 1 ) :
			while ( temp >= arr [ j ] and j >= 0 ) :
				arr [ j + 2 ] = arr [ j ]
				j -= 2
			arr [ j + 2 ] = temp
		else :
			while ( temp <= arr [ j ] and j >= 0 ) :
				arr [ j + 2 ] = arr [ j ]
				j -= 2
			arr [ j + 2 ] = temp
def printArray ( arr , n ) :
	for i in range ( 0 , n ) :
		print ( arr [ i ] , end = " ▁ " )
arr = [ 12 , 11 , 13 , 5 , 6 ]
n = len ( arr )
evenOddInsertionSort ( arr , n )
printArray ( arr , n )