C++算法实源码分析
2015-12-07 19:09
691 查看
includes:
在The C++ Standard Library (second edition, 3rd print)中指出这个算法的复杂度最多是2*(numElems+numSearchElems)-1次比较。
// 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次比较。
相关文章推荐
- 基于wke封装的duilib的webkit浏览器控件,可以c++与js互交,源码及demo下载地址
- C语言总结
- C++ STL中Map的按Key排序和按Value排序
- 深入理解c++中char*与wchar_t*与string以及wstring之间的相互转换
- 【2015广东工业大学新生赛E】【c++函数 bitset读入二进制转十进制数】GDUT的实验室 十进制与二进制的比较
- PInvoke复习之C# C++ 字符串传递
- c++多态性
- 黑马程序员-C语言回顾-字符串
- C++11 的 5 个实用特性
- Huffman学习记录 c语言
- C++类中定义线程
- C++的头文件和实现文件分别写什么
- C/C++语言中函数参数传递的三种方式
- c++设计模式(2)--------简单工厂模式
- 黑马程序员——C语言——位运算符和变量存储原理
- knn之构造kd树和最近邻求取c++实现
- C语言编程中实现输入密码回显星号
- C语言中可变参数的宏定义
- c语言宏定义,可变参数的使用
- C语言中可变参数的宏定义