human
Print array elements in alternatively increasing and decreasing order | Function to print array elements in alternative increasing and decreasing order.
First sort the array in increasing order.
start with 2 elements in increasing order.
till all the elements are not printed.
printing the elements in increasing order.
else : printing the elements in decreasing order.
increasing the number of elements to printed in next iteration.
Driver Code"
Solution in Python:
assistant
#Here is code to print array elements in alternatively increasing and decreasing order and the other steps required.
 def printArray ( arr , n ) :
	arr . sort ( )
	l = 0
	r = n - 1
	flag = 0
	k = 2
	while ( l <= r ) :
		if ( flag == 0 ) :
			i = l
			while i < l + k and i <= r :
				print ( arr [ i ] , end = " ▁ " )
				i += 1
			flag = 1
			l = i
			i = r
			while i > r - k and i >= l :
				print ( arr [ i ] , end = " ▁ " )
				i -= 1
			flag = 0
			r = i
		k += 1
if __name__ == " _ _ main _ _ " :
	n = 6
	arr = [ 1 , 2 , 3 , 4 , 5 , 6 ]
	printArray ( arr , n )