human
Rearrange positive and negative numbers using inbuilt sort function | Python3 implementation of the above approach.
Rearrange the array with all negative integers on left and positive integers on right use recursion to split the array with first element as one half and the rest array as another and then merge it with head of the array in each step.
exit condition.
rearrange the array except the first element in each recursive call.
If the first element of the array is positive , then right - rotate the array by one place first and then reverse the merged array ..
Driver code"
How can the above be solved in Python?
 Give me a code to rearrange positive and negative numbers using inbuilt sort function and the other steps required?
assistant
#Here is code to rearrange positive and negative numbers using inbuilt sort function and the other steps required.
 def printArray ( array , length ) :
	print ( " [ " , end = " " )
	for i in range ( length ) :
		print ( array [ i ] , end = " " ) if ( i < ( length - 1 ) ) : print ( " , " , end = " ▁ " ) else : print ( " ] " )
def reverse ( array , start , end ) :
	while ( start < end ) :
		temp = array [ start ]
		array [ start ] = array [ end ]
		array [ end ] = temp
		start += 1
		end -= 1
def rearrange ( array , start , end ) :
	if ( start == end ) :
		return
	rearrange ( array , ( start + 1 ) , end )
	if ( array [ start ] >= 0 ) :
		reverse ( array , ( start + 1 ) , end )
		reverse ( array , start , end )
if __name__ == ' _ _ main _ _ ' :
	array = [ - 12 , - 11 , - 13 , - 5 , - 6 , 7 , 5 , 3 , 6 ]
	length = len ( array )
	countNegative = 0
	for i in range ( length ) :
		if ( array [ i ] < 0 ) :
			countNegative += 1
	print ( " array : ▁ " , end = " " )
	printArray ( array , length )
	rearrange ( array , 0 , ( length - 1 ) )
	reverse ( array , countNegative , ( length - 1 ) )
	print ( " rearranged ▁ array : ▁ " , end = " " )
	printArray ( array , length )