?? algrithm
字號:
_BI3 _X, _Pr _P)
{for (; ; )
if (_F1 == _L1)
return (copy_backward(_F2, _L2, _X));
else if (_F2 == _L2)
return (copy_backward(_F1, _L1, _X));
else if (_P(*--_L2, *--_L1))
*--_X = *_L1, ++_L2;
else
*--_X = *_L2, ++_L1; }
// TEMPLATE FUNCTION includes
template<class _II1, class _II2> inline
bool includes(_II1 _F1, _II1 _L1, _II2 _F2, _II2 _L2)
{for (; _F1 != _L1 && _F2 != _L2; )
if (*_F2 < *_F1)
return (false);
else if (*_F1 < *_F2)
++_F1;
else
++_F2;
return (_F2 == _L2); }
// TEMPLATE FUNCTION includes WITH PRED
template<class _II1, class _II2, class _Pr> inline
bool includes(_II1 _F1, _II1 _L1, _II2 _F2, _II2 _L2, _Pr _P)
{for (; _F1 != _L1 && _F2 != _L2; )
if (_P(*_F2, *_F1))
return (false);
else if (_P(*_F1, *_F2))
++_F1;
else
++_F2;
return (_F2 == _L2); }
// TEMPLATE FUNCTION set_union
template<class _II1, class _II2, class _OI> inline
_OI set_union(_II1 _F1, _II1 _L1, _II2 _F2, _II2 _L2, _OI _X)
{for (; _F1 != _L1 && _F2 != _L2; )
if (*_F1 < *_F2)
*_X++ = *_F1++;
else if (*_F2 < *_F1)
*_X++ = *_F2++;
else
*_X++ = *_F1++, ++_F2;
return (copy(_F2, _L2, copy(_F1, _L1, _X))); }
// TEMPLATE FUNCTION set_union WITH PRED
template<class _II1, class _II2, class _OI, class _Pr> inline
_OI set_union(_II1 _F1, _II1 _L1, _II2 _F2, _II2 _L2, _OI _X,
_Pr _P)
{for (; _F1 != _L1 && _F2 != _L2; )
if (_P(*_F1, *_F2))
*_X++ = *_F1++;
else if (_P(*_F2, *_F1))
*_X++ = *_F2++;
else
*_X++ = *_F1++, ++_F2;
return (copy(_F2, _L2, copy(_F1, _L1, _X))); }
// TEMPLATE FUNCTION set_intersection
template<class _II1, class _II2, class _OI> inline
_OI set_intersection(_II1 _F1, _II1 _L1, _II2 _F2, _II2 _L2,
_OI _X)
{for (; _F1 != _L1 && _F2 != _L2; )
if (*_F1 < *_F2)
++_F1;
else if (*_F2 < *_F1)
++_F2;
else
*_X++ = *_F1++, ++_F2;
return (_X); }
// TEMPLATE FUNCTION set_intersection WITH PRED
template<class _II1, class _II2, class _OI, class _Pr> inline
_OI set_intersection(_II1 _F1, _II1 _L1, _II2 _F2, _II2 _L2,
_OI _X, _Pr _P)
{for (; _F1 != _L1 && _F2 != _L2; )
if (_P(*_F1, *_F2))
++_F1;
else if (_P(*_F2, *_F1))
++_F2;
else
*_X++ = *_F1++, ++_F2;
return (_X); }
// TEMPLATE FUNCTION set_difference
template<class _II1, class _II2, class _OI> inline
_OI set_difference(_II1 _F1, _II1 _L1, _II2 _F2, _II2 _L2,
_OI _X)
{for (; _F1 != _L1 && _F2 != _L2; )
if (*_F1 < *_F2)
*_X++ = *_F1++;
else if (*_F2 < *_F1)
++_F2;
else
++_F1, ++_F2;
return (copy(_F1, _L1, _X)); }
// TEMPLATE FUNCTION set_difference WITH PRED
template<class _II1, class _II2, class _OI, class _Pr> inline
_OI set_difference(_II1 _F1, _II1 _L1, _II2 _F2, _II2 _L2,
_OI _X, _Pr _P)
{for (; _F1 != _L1 && _F2 != _L2; )
if (_P(*_F1, *_F2))
*_X++ = *_F1++;
else if (_P(*_F2, *_F1))
++_F2;
else
++_F1, ++_F2;
return (copy(_F1, _L1, _X)); }
// TEMPLATE FUNCTION set_symmetric_difference
template<class _II1, class _II2, class _OI> inline
_OI set_symmetric_difference(_II1 _F1, _II1 _L1, _II2 _F2,
_II2 _L2, _OI _X)
{for (; _F1 != _L1 && _F2 != _L2; )
if (*_F1 < *_F2)
*_X++ = *_F1++;
else if (*_F2 < *_F1)
*_X++ = *_F2++;
else
++_F1, ++_F2;
return (copy(_F2, _L2, copy(_F1, _L1, _X))); }
// TEMPLATE FUNCTION set_symmetric_difference WITH PRED
template<class _II1, class _II2, class _OI, class _Pr> inline
_OI set_symmetric_difference(_II1 _F1, _II1 _L1, _II2 _F2,
_II2 _L2, _OI _X, _Pr _P)
{for (; _F1 != _L1 && _F2 != _L2; )
if (_P(*_F1, *_F2))
*_X++ = *_F1++;
else if (_P(*_F2, *_F1))
*_X++ = *_F2++;
else
++_F1, ++_F2;
return (copy(_F2, _L2, copy(_F1, _L1, _X))); }
// TEMPLATE FUNCTION push_heap
template<class _RI> inline
void push_heap(_RI _F, _RI _L)
{_Push_heap_0(_F, _L, _Dist_type(_F), _Val_type(_F)); }
template<class _RI, class _Pd, class _Ty> inline
void _Push_heap_0(_RI _F, _RI _L, _Pd *, _Ty *)
{_Push_heap(_F, _Pd(_L - _F - 1), _Pd(0), _Ty(*(_L - 1))); }
template<class _RI, class _Pd, class _Ty> inline
void _Push_heap(_RI _F, _Pd _H, _Pd _J, _Ty _V)
{for (_Pd _I = (_H - 1) / 2; _J < _H && *(_F + _I) < _V;
_I = (_H - 1) / 2)
*(_F + _H) = *(_F + _I), _H = _I;
*(_F + _H) = _V; }
// TEMPLATE FUNCTION push_heap WITH PRED
template<class _RI, class _Pr> inline
void push_heap(_RI _F, _RI _L, _Pr _P)
{_Push_heap_0(_F, _L, _P,
_Dist_type(_F), _Val_type(_F)); }
template<class _RI, class _Pd, class _Ty, class _Pr> inline
void _Push_heap_0(_RI _F, _RI _L, _Pr _P, _Pd *, _Ty *)
{_Push_heap(_F, _Pd(_L - _F - 1), _Pd(0),
_Ty(*(_L - 1)), _P); }
template<class _RI, class _Pd, class _Ty, class _Pr> inline
void _Push_heap(_RI _F, _Pd _H, _Pd _J, _Ty _V, _Pr _P)
{for (_Pd _I = (_H - 1) / 2; _J < _H && _P(*(_F + _I), _V);
_I = (_H - 1) / 2)
*(_F + _H) = *(_F + _I), _H = _I;
*(_F + _H) = _V; }
// TEMPLATE FUNCTION pop_heap
template<class _RI> inline
void pop_heap(_RI _F, _RI _L)
{_Pop_heap_0(_F, _L, _Val_type(_F)); }
template<class _RI, class _Ty> inline
void _Pop_heap_0(_RI _F, _RI _L, _Ty *)
{_Pop_heap(_F, _L - 1, _L - 1, _Ty(*(_L - 1)),
_Dist_type(_F)); }
template<class _RI, class _Pd, class _Ty> inline
void _Pop_heap(_RI _F, _RI _L, _RI _X, _Ty _V, _Pd *)
{*_X = *_F;
_Adjust_heap(_F, _Pd(0), _Pd(_L - _F), _V); }
template<class _RI, class _Pd, class _Ty> inline
void _Adjust_heap(_RI _F, _Pd _H, _Pd _N, _Ty _V)
{_Pd _J = _H;
_Pd _K = 2 * _H + 2;
for (; _K < _N; _K = 2 * _K + 2)
{if (*(_F + _K) < *(_F + (_K - 1)))
--_K;
*(_F + _H) = *(_F + _K), _H = _K; }
if (_K == _N)
*(_F + _H) = *(_F + (_K - 1)), _H = _K - 1;
_Push_heap(_F, _H, _J, _V); }
// TEMPLATE FUNCTION pop_heap WITH PRED
template<class _RI, class _Pr> inline
void pop_heap(_RI _F, _RI _L, _Pr _P)
{_Pop_heap_0(_F, _L, _P, _Val_type(_F)); }
template<class _RI, class _Ty, class _Pr> inline
void _Pop_heap_0(_RI _F, _RI _L, _Pr _P, _Ty *)
{_Pop_heap(_F, _L - 1, _L - 1, _Ty(*(_L - 1)), _P,
_Dist_type(_F)); }
template<class _RI, class _Pd, class _Ty, class _Pr> inline
void _Pop_heap(_RI _F, _RI _L, _RI _X, _Ty _V, _Pr _P, _Pd *)
{*_X = *_F;
_Adjust_heap(_F, _Pd(0), _Pd(_L - _F), _V, _P); }
template<class _RI, class _Pd, class _Ty, class _Pr> inline
void _Adjust_heap(_RI _F, _Pd _H, _Pd _N, _Ty _V, _Pr _P)
{_Pd _J = _H;
_Pd _K = 2 * _H + 2;
for (; _K < _N; _K = 2 * _K + 2)
{if (_P(*(_F + _K), *(_F + (_K - 1))))
--_K;
*(_F + _H) = *(_F + _K), _H = _K; }
if (_K == _N)
*(_F + _H) = *(_F + (_K - 1)), _H = _K - 1;
_Push_heap(_F, _H, _J, _V, _P); }
// TEMPLATE FUNCTION make_heap
template<class _RI> inline
void make_heap(_RI _F, _RI _L)
{if (2 <= _L - _F)
_Make_heap(_F, _L, _Dist_type(_F), _Val_type(_F)); }
template<class _RI, class _Pd, class _Ty> inline
void _Make_heap(_RI _F, _RI _L, _Pd *, _Ty *)
{_Pd _N = _L - _F;
for (_Pd _H = _N / 2; 0 < _H; )
--_H, _Adjust_heap(_F, _H, _N, _Ty(*(_F + _H))); }
// TEMPLATE FUNCTION make_heap WITH PRED
template<class _RI, class _Pr> inline
void make_heap(_RI _F, _RI _L, _Pr _P)
{if (2 <= _L - _F)
_Make_heap(_F, _L, _P,
_Dist_type(_F), _Val_type(_F)); }
template<class _RI, class _Pd, class _Ty, class _Pr> inline
void _Make_heap(_RI _F, _RI _L, _Pr _P, _Pd *, _Ty *)
{_Pd _N = _L - _F;
for (_Pd _H = _N / 2; 0 < _H; )
--_H, _Adjust_heap(_F, _H, _N, _Ty(*(_F + _H)), _P); }
// TEMPLATE FUNCTION sort_heap
template<class _RI> inline
void sort_heap(_RI _F, _RI _L)
{for (; 1 < _L - _F; --_L)
pop_heap(_F, _L); }
// TEMPLATE FUNCTION sort_heap WITH PRED
template<class _RI, class _Pr> inline
void sort_heap(_RI _F, _RI _L, _Pr _P)
{for (; 1 < _L - _F; --_L)
pop_heap(_F, _L, _P); }
// TEMPLATE FUNCTION max_element
template<class _FI> inline
_FI max_element(_FI _F, _FI _L)
{_FI _X = _F;
if (_F != _L)
for (; ++_F != _L; )
if (*_X < *_F)
_X = _F;
return (_X); }
// TEMPLATE FUNCTION max_element WITH PRED
template<class _FI, class _Pr> inline
_FI max_element(_FI _F, _FI _L, _Pr _P)
{_FI _X = _F;
if (_F != _L)
for (; ++_F != _L; )
if (_P(*_X, *_F))
_X = _F;
return (_X); }
// TEMPLATE FUNCTION min_element
template<class _FI> inline
_FI min_element(_FI _F, _FI _L)
{_FI _X = _F;
if (_F != _L)
for (; ++_F != _L; )
if (*_F < *_X)
_X = _F;
return (_X); }
// TEMPLATE FUNCTION min_element WITH PRED
template<class _FI, class _Pr> inline
_FI min_element(_FI _F, _FI _L, _Pr _P)
{_FI _X = _F;
if (_F != _L)
for (; ++_F != _L; )
if (_P(*_F, *_X))
_X = _F;
return (_X); }
// TEMPLATE FUNCTION next_permutation
template<class _BI> inline
bool next_permutation(_BI _F, _BI _L)
{_BI _I = _L;
if (_F == _L || _F == --_I)
return (false);
for (; ; )
{_BI _Ip = _I;
if (*--_I < *_Ip)
{_BI _J = _L;
for (; !(*_I < *--_J); )
;
iter_swap(_I, _J);
reverse(_Ip, _L);
return (true); }
if (_I == _F)
{reverse(_F, _L);
return (false); }}}
// TEMPLATE FUNCTION next_permutation WITH PRED
template<class _BI, class _Pr> inline
bool next_permutation(_BI _F, _BI _L, _Pr _P)
{_BI _I = _L;
if (_F == _L || _F == --_I)
return (false);
for (; ; )
{_BI _Ip = _I;
if (_P(*--_I, *_Ip))
{_BI _J = _L;
for (; !_P(*_I, *--_J); )
;
iter_swap(_I, _J);
reverse(_Ip, _L);
return (true); }
if (_I == _F)
{reverse(_F, _L);
return (false); }}}
// TEMPLATE FUNCTION prev_permutation
template<class _BI> inline
bool prev_permutation(_BI _F, _BI _L)
{_BI _I = _L;
if (_F == _L || _F == --_I)
return (false);
for (; ; )
{_BI _Ip = _I;
if (!(*--_I < *_Ip))
{_BI _J = _L;
for (; *_I < *--_J; )
;
iter_swap(_I, _J);
reverse(_Ip, _L);
return (true); }
if (_I == _F)
{reverse(_F, _L);
return (false); }}}
// TEMPLATE FUNCTION prev_permutation WITH PRED
template<class _BI, class _Pr> inline
bool prev_permutation(_BI _F, _BI _L, _Pr _P)
{_BI _I = _L;
if (_F == _L || _F == --_I)
return (false);
for (; ; )
{_BI _Ip = _I;
if (!_P(*--_I, *_Ip))
{_BI _J = _L;
for (; _P(*_I, *--_J); )
;
iter_swap(_I, _J);
reverse(_Ip, _L);
return (true); }
if (_I == _F)
{reverse(_F, _L);
return (false); }}}
_STD_END
#ifdef _MSC_VER
#pragma pack(pop)
#endif /* _MSC_VER */
#endif /* _ALGORITHM_ */
/*
* Copyright (c) 1995 by P.J. Plauger. ALL RIGHTS RESERVED.
* Consult your license regarding permissions and restrictions.
*/
/*
* This file is derived from software bearing the following
* restrictions:
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Permission to use, copy, modify, distribute and sell this
* software and its documentation for any purpose is hereby
* granted without fee, provided that the above copyright notice
* appear in all copies and that both that copyright notice and
* this permission notice appear in supporting documentation.
* Hewlett-Packard Company makes no representations about the
* suitability of this software for any purpose. It is provided
* "as is" without express or implied warranty.
*/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -