You have a vector of size N and want to rotate it i places to the left. For example : the vector is abcdefgh, of size 8, and you want to rotate it by 3 places to make it defghabc. The book discusses 3 methods.
Method 1:
It is called the 'juggling method'. We’ll use a temporary location t
and move all the vector elements left in hops of i, as follows: move
x[0] to t, then move x[i] to x[0], x[2i] to x[i], and so on (the
indices into x are taken modulo n). Eventually we’ll come back to x[0],
at which point we instead take the element from t and end the process.
If that process didn’t move all the elements, then we start over at
x[1] and repeat, until we move all the elements.
Here is a c++ source code. 'vec' is the original vector, 'N' is the size of vec, and 'I' is the rotation distance.

Method 2:
Swapping: Rotating the vector x is really just swapping the two
segments of the vector ab to the vector ba, where a represents the
first i elements of x. Suppose a is shorter than b. Divide b into b_r
and b_l, so that b_r is the same length as a. Swap a and b_r to
transform a.b_l.b_r into b_r.b_l.a. The sequence a is in its final
place, so we can focus on swapping the two parts of b. Since this new
problem has the same form as the original, we can solve it recursively.
Here is a c++ source code.


Method 3:
Here's the 'aha' solution. if you want to rotate a vector 'ab' to form 'ba', the solution is reverse(reverse(a)reverse(b)).
Here is a C++ code.

