human
What is a code to sort first half in ascending and second half in descending order and the other steps required given the following:
Sort first half in ascending and second half in descending order | 1 | function to print half of the array in ascending order and the other half in descending order.
sorting the array.
printing first half in ascending order.
printing second half in descending order.
Driver code"
Solution in Python:
assistant
#Here is code to sort first half in ascending and second half in descending order and the other steps required.
 def printOrder ( arr , n ) :
	arr . sort ( )
	for i in range ( n // 2 ) :
		print ( arr [ i ] , end = " ▁ " )
	for j in range ( n - 1 , n // 2 - 1 , - 1 ) :
		print ( arr [ j ] , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
	arr = [ 5 , 4 , 6 , 2 , 1 , 3 , 8 , - 1 ]
	n = len ( arr )
	printOrder ( arr , n )