Positive elements at even and negative at odd positions ( Relative order not maintained ) | Print array function ; Driver code ; before modification ; out of order positive element ; find out of order negative element in remaining array ; out of order negative element ; find out of order positive element in remaining array ; after modification
def printArray ( a , n ) : NEW_LINE INDENT for i in a : NEW_LINE INDENT print ( i , end = " ▁ " ) NEW_LINE DEDENT print ( ) NEW_LINE DEDENT arr = [ 1 , - 3 , 5 , 6 , - 3 , 6 , 7 , - 4 , 9 , 10 ] NEW_LINE n = len ( arr ) NEW_LINE printArray ( arr , n ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( arr [ i ] >= 0 and i % 2 == 1 ) : NEW_LINE INDENT for j in range ( i + 1 , n ) : NEW_LINE INDENT if ( arr [ j ] < 0 and j % 2 == 0 ) : NEW_LINE INDENT arr [ i ] , arr [ j ] = arr [ j ] , arr [ i ] NEW_LINE break NEW_LINE DEDENT DEDENT DEDENT elif ( arr [ i ] < 0 and i % 2 == 0 ) : NEW_LINE INDENT for j in range ( i + 1 , n ) : NEW_LINE INDENT if ( arr [ j ] >= 0 and j % 2 == 1 ) : NEW_LINE INDENT arr [ i ] , arr [ j ] = arr [ j ] , arr [ i ] NEW_LINE break NEW_LINE DEDENT DEDENT DEDENT DEDENT printArray ( arr , n ) ; NEW_LINE