human
Program to print an array in Pendulum Arrangement with constant space | Function to print the Pendulum arrangement of the given array.
Sort the array.
pos stores the index of the last element of the array.
odd stores the last odd index in the array.
Move all odd index positioned elements to the right.
Shift the elements by one position from odd to pos.
Reverse the element from 0 to ( n - 1 ) / 2.
Printing the pendulum arrangement.
Driver code"
Solution in Python:
 ... Write me a code to program to print an array in Pendulum Arrangement with constant space and the other steps required?
assistant
#Here is code to program to print an array in Pendulum Arrangement with constant space and the other steps required.
 def pendulumArrangement ( arr , n ) :
	arr . sort ( reverse = False )
	pos = n - 1
	if ( n % 2 == 0 ) :
		odd = n - 1
	else :
		odd = n - 2
	while ( odd > 0 ) :
		temp = arr [ odd ]
		in1 = odd
		while ( in1 != pos ) :
			arr [ in1 ] = arr [ in1 + 1 ]
			in1 += 1
		arr [ in1 ] = temp
		odd = odd - 2
		pos = pos - 1
	start = 0
	end = int ( ( n - 1 ) / 2 )
	while ( start < end ) :
		temp = arr [ start ]
		arr [ start ] = arr [ end ]
		arr [ end ] = temp
		start += 1
		end -= 1
	for i in range ( n ) :
		print ( arr [ i ] , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
	arr = [ 11 , 2 , 4 , 55 , 6 , 8 ]
	n = len ( arr )
	pendulumArrangement ( arr , n )