# rotate(3C++)

**rotate --
circularly rotate the elements of an array
**

## Synopsis

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);

## Assumptions

(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=**.

## Description

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**.

## Complexity

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.

## Notes

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.

## References

**Array_alg**(3C++),
**Block**(3C++),

*
© 2004 The SCO Group, Inc. All rights reserved.
*

UnixWare 7 Release 7.1.4 - 25 April 2004