text: Print all possible rotations of a 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: arr = Array . from ( { length : 10000 } , ( _ , i ) => 0 ) ; function reverse ( arr , s , e ) { while ( s < e ) { var tem = arr [ s ] ; arr [ s ] = arr [ e ] ; arr [ e ] = tem ; s = s + 1 ; e = e - 1 ; } } function fun ( arr , k ) { var n = 4 - 1 ; var v = n - k ; if ( v >= 0 ) { reverse ( arr , 0 , v ) ; reverse ( arr , v + 1 , n ) ; reverse ( arr , 0 , n ) ; } } arr [ 0 ] = 1 ; arr [ 1 ] = 2 ; arr [ 2 ] = 3 ; arr [ 3 ] = 4 ; for ( i = 0 ; i < 4 ; i ++ ) { fun ( arr , i ) ; document . write ( " " ) ; for ( j = 0 ; j < 4 ; j ++ ) { document . write ( arr [ j ] + " " ) ; } document . write ( " " ) ; }