- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
// TEMPLATE FUNCTION rotate
template<class _FI> inline
void rotate(_FI _F, _FI _M, _FI _L)
{if (_F != _M && _M != _L)
_Rotate(_F, _M, _L, _Iter_cat(_F)); }
template<class _FI> inline
void _Rotate(_FI _F, _FI _M, _FI _L,
forward_iterator_tag)
{for (_FI _X = _M; ; )
{iter_swap(_F, _X);
if (++_F == _M)
if (++_X == _L)
break;
else
_M = _X;
else if (++_X == _L)
_X = _M; }}
template<class _BI> inline
void _Rotate(_BI _F, _BI _M, _BI _L,
bidirectional_iterator_tag)
{reverse(_F, _M);
reverse(_M, _L);
reverse(_F, _L); }
template<class _RI> inline
void _Rotate(_RI _F, _RI _M, _RI _L,
random_access_iterator_tag)
{_Rotate(_F, _M, _L, _Dist_type(_F), _Val_type(_F)); }
template<class _RI, class _Pd, class _Ty> inline
void _Rotate(_RI _F, _RI _M, _RI _L, _Pd *, _Ty *)
{_Pd _D = _M - _F;
_Pd _N = _L - _F;
for (_Pd _I = _D; _I != 0; )
{_Pd _J = _N % _I;
_N = _I, _I = _J; }
if (_N < _L - _F)
for (; 0 < _N; --_N)
{_RI _X = _F + _N;
_RI _Y = _X;
_Ty _V = *_X;
_RI _Z = _Y + _D == _L ? _F : _Y + _D;
while (_Z != _X)
{*_Y = *_Z;
_Y = _Z;
_Z = _D < _L - _Z ? _Z + _D
: _F + (_D - (_L - _Z)); }
*_Y = _V; }}