human
Sort Array such that smallest is at 0 th index and next smallest it at last index and so on | Python3 program for the above approach Function to perform the rearrangement.
Initialize variables.
Loop until i crosses j.
This check is to find the minimum values in the ascending order.
Condition to alternatively iterate variable i and j.
Perform swap operation.
Increment i.
Assign the value of min.
Perform swap.
Decrement i.
Assign the value of min.
Print the array.
Driver Code.
Given Array arr [ ].
Function call"
Solution in Python:
 What is a code to sort Array such that smallest is at 0 th index and next smallest it at last index and so on and the other steps required?
assistant
#Here is code to sort Array such that smallest is at 0 th index and next smallest it at last index and so on and the other steps required.
 def rearrange ( a , N ) :
	i = 0
	j = N - 1
	min = 0
	x = 0
	while ( i < j ) :
		for k in range ( i , j + 1 ) :
			if ( a [ k ] < a [ min ] ) :
				min = k
		if ( x % 2 == 0 ) :
			temp = a [ i ]
			a [ i ] = a [ min ]
			a [ min ] = temp
			i += 1
			min = i
		else :
			temp = a [ j ]
			a [ j ] = a [ min ]
			a [ min ] = temp
			j -= 1
			min = j
		x += 1
	for i in range ( N ) :
		print ( a [ i ] , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
	arr = [ 1 , 3 , 3 , 4 , 5 ]
	N = len ( arr )
	rearrange ( arr , N )