Split the array and add the first part to the end | CPP program to split array and move first part to end . ; Function to spilt array and move first part to end ; make a temporary array with double the size ; copy array element in to new array twice ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void splitArr ( int arr [ ] , int length , int rotation ) { int tmp [ length * 2 ] = { 0 } ; for ( int i = 0 ; i < length ; i ++ ) { tmp [ i ] = arr [ i ] ; tmp [ i + length ] = arr [ i ] ; } for ( int i = rotation ; i < rotation + length ; i ++ ) { arr [ i - rotation ] = tmp [ i ] ; } } int main ( ) { int arr [ ] = { 12 , 10 , 5 , 6 , 52 , 36 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int position = 2 ; splitArr ( arr , n , position ) ; for ( int i = 0 ; i < n ; ++ i ) printf ( " % d ▁ " , arr [ i ] ) ; return 0 ; }