To clear the data of previous steps
arr_s . clear ( ) ; for ( int i = 0 ; i < arr . size ( ) ; i += 2 ) { if ( i == arr . size ( ) - 1 ) arr_s . push_back ( arr [ i ] ) ; else arr_s . push_back ( mergeTwoArrays ( arr [ i ] , arr [ i + 1 ] ) ) ; } arr = arr_s ; }