human
Sort an array when two halves are sorted | Merge two sorted halves of Array into single sorted array.
Starting index of second half.
Temp Array store sorted resultant array.
First Find the point where array is divide into two half.
If Given array is all - ready sorted.
Merge two sorted arrays in single sorted array.
Copy the remaining elements of A [ i to half_ ! ].
Copy the remaining elements of A [ half_ ! to n ].
Driver code.
Print sorted Array"
Solution in Python:
 ... Write me a code to sort an array when two halves are sorted and the other steps required?
assistant
#Here is code to sort an array when two halves are sorted and the other steps required.
 def mergeTwoHalf ( A , n ) :
	half_i = 0
	temp = [ 0 for i in range ( n ) ]
	for i in range ( n - 1 ) :
		if ( A [ i ] > A [ i + 1 ] ) :
			half_i = i + 1
			break
	if ( half_i == 0 ) :
		return
	i = 0
	j = half_i
	k = 0
	while ( i < half_i and j < n ) :
		if ( A [ i ] < A [ j ] ) :
			temp [ k ] = A [ i ]
			k += 1
			i += 1
		else :
			temp [ k ] = A [ j ]
			k += 1
			j += 1
	while i < half_i :
		temp [ k ] = A [ i ]
		k += 1
		i += 1
	while ( j < n ) :
		temp [ k ] = A [ j ]
		k += 1
		j += 1
	for i in range ( n ) :
		A [ i ] = temp [ i ]
A = [ 2 , 3 , 8 , - 1 , 7 , 10 ]
n = len ( A )
mergeTwoHalf ( A , n )
print ( * A , sep = ' ▁ ' )