|
|
template <class T> void rotate(ptrdiff_t n,T* b,T* e); template <class T> void rotate_c(ptrdiff_t n,T* b1,T* e1,T* b2);
(1) For the copy version, the output array does not overlap the input array.
(2) For the copy version, the output array has at least as many cells as the input array.
(3) T has operator=.
These functions circularly rotate the elements of an array. If n is positive, the elements are rotated n places to the right; if n is negative, the elements are rotated -n places to the left. That is, for every integer i between 0 and e-b-1 the value at location b+i after rotation will equal the value at location b+(i+n)*(e%b) before rotation.
template <class T> void rotate(ptrdiff_t n,T* b,T* e);
Rotates the array in place.
template <class T> void rotate_c(ptrdiff_t n,T* b1,T* e1,T* b2);
Like rotate except that the input array is preserved and the result is written to a new array beginning at location b2.
If N is the size of the array, then complexity is O(N). More precisely,
plain version
Approximately 3N assignments are done.
copy version
Exactly N assignments are done.
Because a Block (see Block(3C++)) can always be used wherever an array is called for, Array Algorithms can also be used with Blocks. In fact, these two components were actually designed to be used together.