human
Sort an array without changing position of negative numbers | Function to sort the array such that negative values do not get affected.
Store all non - negative values.
Sort non - negative values.
If current element is non - negative then update it such that all the non - negative values are sorted.
Print the sorted array.
Driver code"
Solution in Python:
assistant
#Here is code to sort an array without changing position of negative numbers and the other steps required.
 def sortArray ( a , n ) :
	ans = [ ]
	for i in range ( n ) :
		if ( a [ i ] >= 0 ) :
			ans . append ( a [ i ] )
	ans = sorted ( ans )
	j = 0
	for i in range ( n ) :
		if ( a [ i ] >= 0 ) :
			a [ i ] = ans [ j ]
			j += 1
	for i in range ( n ) :
		print ( a [ i ] , end = " ▁ " )
arr = [ 2 , - 6 , - 3 , 8 , 4 , 1 ]
n = len ( arr )
sortArray ( arr , n )