How does rotate work?

how is rotation 10 20 30 40 50 about 30 40 50 10 20?

If you rotate this array onece… it will be 50 10 20 30 40
2nd rotation 40 50 10 20 30
3rd rotation 30 40 50 10 20
For an optimal approach to rotate an array, refer this http://www.interviewdruid.com/rotate-an-array/

The function is defined in header . It rotates the order of the elements in the range [first,last], in such a way that the element pointed by middle becomes the new first element.

  1. Left Rotation : To rotate left, we need to add the vector index. For example, you have to rotate vector left 3 times. The 3th index of vector becomes first element. vec.begin() + 3 will rotate vector 3 times left.
  2. Right Rotation : To rotate right, we need to subtract the vector index. For example, you have to rotate vector right 3 times. The 3th last index of vector becomes first element. vec.begin()+vec.size()-3 will rotate vector 3 times right.
    Input : 1 2 3 4 5 6 7 8 9
    Output :
    Old vector : 1 2 3 4 5 6 7 8 9
    New vector : 4 5 6 7 8 9 1 2 3 // Rotated at 3th position, starting index as 0.

Input : 8 2 4 6 11 0 15 8
Output :
Old vector : 8 2 4 6 11 0 15 8
New vector : 0 15 8 8 2 4 6 11 //Rotated at 5th position, starting index as 0.
reference
cplusplus.com/reference/algorithm/rotate/

why you have rotated the array three time ?
and pls explain the arguments of the function rotate

by default, it rotates about the middle element

read the second example, and rotate three times about the center element, u will understand