13. The order of the array so that the adjustment in front of even-odd
problem:
Enter an array of integers, to realize a function to adjust the order of the numbers in the array, such that all the odd part of the front half of the array, is located in the second half of all the even array, and between odd and ensure a relatively even, odd and even the same position.
solve:
thought:
This question is the focus of that sort -> stable. We directly employ bubble sort to sort the array, because bubble sort is stable.
python code:
class Solution:
def reOrderArray(self, array):
# write code here
n=len(array)
for i in range(n-1):
for j in range(n-i-1):
if(array[j]%2==0 and array[j+1]%2!=0):
array[j],array[j+1]=array[j+1],array[j]
return array