您的位置:首页 > 编程语言 > C语言/C++

C++算法实源码分析

2015-12-07 19:09 691 查看
includes:

// TEMPLATE FUNCTION includes WITH PRED
template<class _InIt1,
class _InIt2,
class _Pr> inline
bool _Includes(_InIt1 _First1, _InIt1 _Last1,
_InIt2 _First2, _InIt2 _Last2, _Pr _Pred)
{    // test if set [_First1, _Last1) in [_First2, _Last2), using _Pred
for (; _First1 != _Last1 && _First2 != _Last2; )
if (_DEBUG_LT_PRED(_Pred, *_First2, *_First1))
return (false);
else if (_Pred(*_First1, *_First2))
++_First1;
else
{    // advance both
++_First1;
++_First2;
}
return (_First2 == _Last2);
}

template<class _InIt1,
class _InIt2,
class _Pr> inline
bool includes(_InIt1 _First1, _InIt1 _Last1,
_InIt2 _First2, _InIt2 _Last2, _Pr _Pred)
{    // test if set [_First1, _Last1) in [_First2, _Last2), using _Pred
_DEBUG_ORDER_PRED(_First1, _Last1, _Pred);
_DEBUG_ORDER_PRED(_First2, _Last2, _Pred);
return (_Includes(_Unchecked(_First1), _Unchecked(_Last1),
_Unchecked(_First2), _Unchecked(_Last2), _Pred));
}

// TEMPLATE FUNCTION includes
template<class _InIt1,
class _InIt2> inline
bool includes(_InIt1 _First1, _InIt1 _Last1,
_InIt2 _First2, _InIt2 _Last2)
{    // test if all [_First1, _Last1) in [_First2, _Last2), using operator<
return (_STD includes(_First1, _Last1, _First2, _Last2,
less<>()));
}

在The C++ Standard Library (second edition, 3rd print)中指出这个算法的复杂度最多是2*(numElems+numSearchElems)-1次比较。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: