text: Print all possible rotations of a given Array | C # program to print all possible rotations of the given array ; Global declaration of array ; Function to reverse array between indices s and e ; Function to generate all possible rotations of array ; Driver code
code: using System ; class GFG { static int [ ] arr = new int [ 10000 ] ; public static void reverse ( int [ ] arr , int s , int e ) { while ( s < e ) { int tem = arr [ s ] ; arr [ s ] = arr [ e ] ; arr [ e ] = tem ; s = s + 1 ; e = e - 1 ; } } public static void fun ( int [ ] arr , int k ) { int n = 4 - 1 ; int v = n - k ; if ( v >= 0 ) { reverse ( arr , 0 , v ) ; reverse ( arr , v + 1 , n ) ; reverse ( arr , 0 , n ) ; } } public static void Main ( String [ ] args ) { arr [ 0 ] = 1 ; arr [ 1 ] = 2 ; arr [ 2 ] = 3 ; arr [ 3 ] = 4 ; for ( int i = 0 ; i < 4 ; i ++ ) { fun ( arr , i ) ; Console . Write ( " [ " ) ; for ( int j = 0 ; j < 4 ; j ++ ) { Console . Write ( arr [ j ] + " , ▁ " ) ; } Console . Write ( " ] " ) ; } } }