Rotate all odd numbers right and all even numbers left in an Array of 1 to N | C # program to implement the above approach ; Function to left rotate ; Function to right rotate ; Function to rotate the array ; Driver code
using System ; class GFG { static void left_rotate ( int [ ] arr ) { int last = arr [ 1 ] ; for ( int i = 3 ; i < arr . Length ; i = i + 2 ) { arr [ i - 2 ] = arr [ i ] ; } arr [ arr . Length - 1 ] = last ; } static void right_rotate ( int [ ] arr ) { int start = arr [ arr . Length - 2 ] ; for ( int i = arr . Length - 4 ; i >= 0 ; i = i - 2 ) { arr [ i + 2 ] = arr [ i ] ; } arr [ 0 ] = start ; } public static void rotate ( int [ ] arr ) { left_rotate ( arr ) ; right_rotate ( arr ) ; for ( int i = 0 ; i < arr . Length ; i ++ ) { Console . Write ( arr [ i ] + " ▁ " ) ; } } public static void Main ( ) { int [ ] arr = { 1 , 2 , 3 , 4 , 5 , 6 } ; rotate ( arr ) ; } }