Reverse an array without using subtract sign â €˜ | Function to reverse array ; Trick to assign - 1 to a variable ; Reverse array in simple manner ; Swap ith index value with ( n - i - 1 ) th index value ; Driver code ; print the reversed array
def reverseArray ( arr , n ) : NEW_LINE INDENT import sys NEW_LINE x = - sys . maxsize // sys . maxsize NEW_LINE for i in range ( n // 2 ) : NEW_LINE INDENT arr [ i ] , arr [ n + ( x * i ) + x ] = arr [ n + ( x * i ) + x ] , arr [ i ] NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 5 , 3 , 7 , 2 , 1 , 6 ] NEW_LINE n = len ( arr ) NEW_LINE reverseArray ( arr , n ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT print ( arr [ i ] , end = " ▁ " ) NEW_LINE DEDENT DEDENT