human
A sorting algorithm that slightly improves on selection sort | Python3 program to implement min max selection sort ..
shifting the min ..
Shifting the max . The equal condition happens if we shifted the max to arr [ min_i ] in the previous swap ..
Driver code"
Solution in Python:
 Give me a code to a sorting algorithm that slightly improves on selection sort and the other steps required?
assistant
#Here is code to a sorting algorithm that slightly improves on selection sort and the other steps required.
 def minMaxSelectionSort ( arr , n ) :
	i = 0
	j = n - 1
	while ( i < j ) :
		min = arr [ i ]
		max = arr [ i ]
		min_i = i
		max_i = i
		for k in range ( i , j + 1 , 1 ) :
			if ( arr [ k ] > max ) :
				max = arr [ k ]
				max_i = k
			elif ( arr [ k ] < min ) :
				min = arr [ k ]
				min_i = k
		temp = arr [ i ]
		arr [ i ] = arr [ min_i ]
		arr [ min_i ] = temp
		if ( arr [ min_i ] == max ) :
			temp = arr [ j ]
			arr [ j ] = arr [ min_i ]
			arr [ min_i ] = temp
		else :
			temp = arr [ j ]
			arr [ j ] = arr [ max_i ]
			arr [ max_i ] = temp
		i += 1
		j -= 1
	print ( " Sorted ▁ array : " , end = " ▁ " )
	for i in range ( n ) :
		print ( arr [ i ] , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
	arr = [ 23 , 78 , 45 , 8 , 32 , 56 , 1 ]
	n = len ( arr )
	minMaxSelectionSort ( arr , n )