cb29a_c++_STL_算法_查找算法_(2)search_n
//比如:连续查找连续的n个8
search_n(b,e,c,v),迭代器b,begin(),e,end().连续的c个v
pos=search_n(ideq.begin(), ideq.end(), 4, 3);

search_n(b,e,c,v,p) p,谓词参数,查找的规则(条件)
pos = search_n(ideq.begin(), ideq.end(), 3, 6, greater<int>());
greater<int>(),预定义函数对象。
自己做谓词,需要用二元谓词,就是两个参数的。

特别注意:
该算法的第二种形式应该是:
search_n_if(b,e,c,p)//实际不能使用,委员会审查,未发现,估计是bug.
pos=search_n_if(ideq.begin(),ideq.end(),3,bind2nd(greater<int>(),6));//实际不能使用
等效于
pos = search_n(ideq.begin(), ideq.end(), 3, 6, greater<int>());//这个可以。

distance算法
cout << "找到了连续的4个3: 当前位置:" << distance(ideq.begin(),pos)+1 << endl;

 /*cb29a_c++_STL_算法_查找算法_(2)search_n
//比如:连续查找连续的n个8
search_n(b,e,c,v),迭代器b,begin(),e,end().连续的c个v
pos=search_n(ideq.begin(), ideq.end(), 4, 3); search_n(b,e,c,v,p) p,谓词参数,查找的规则(条件)
pos = search_n(ideq.begin(), ideq.end(), 3, 6, greater<int>());
greater<int>(),预定义函数对象。
自己做谓词,需要用二元谓词,就是两个参数的。 特别注意:
该算法的第二种形式应该是:
search_n_if(b,e,c,p)//实际不能使用,委员会审查,未发现,估计是bug.
pos=search_n_if(ideq.begin(),ideq.end(),3,bind2nd(greater<int>(),6));//实际不能使用
等效于
pos = search_n(ideq.begin(), ideq.end(), 3, 6, greater<int>());//这个可以。 distance算法
cout << "找到了连续的4个3: 当前位置:" << distance(ideq.begin(),pos)+1 << endl;
*/ #include <iostream>
#include <algorithm>
#include <deque>
#include <functional> using namespace std; int main()
{
deque<int> ideq;
for (int i = ; i <= ; ++i)
{
if (i == )
{
ideq.push_back(i);
ideq.push_back(i);
ideq.push_back(i);
//ideq.push_back(i);
}
else
ideq.push_back(i);
}
for (deque<int>::iterator iter = ideq.begin(); iter != ideq.end(); ++iter)
cout << *iter << ' ';
cout << endl; deque<int>::iterator pos;
pos=search_n(ideq.begin(), ideq.end(), , );
if (pos != ideq.end())
{
cout << "找到了连续的4个3: 当前序号位置:" << distance(ideq.begin(),pos)+ << endl;
}
else
cout << "没有找到" << endl; cout << "连续的3个大于的6的数" << endl;
pos = search_n(ideq.begin(), ideq.end(), , , greater<int>());
//pos = search_n_if(ideq.begin(), ideq.end(), 3, bind2nd(greater<int>(), 6));//错误//实际不能使用
if (pos != ideq.end())
{
cout << "连续的3个大于的6的数,当前序号位置:" << distance(ideq.begin(), pos) + << endl;
}
else
cout << "没有找到" << endl; return ;
}

cb29a_c++_STL_算法_查找算法_(2)search_n的更多相关文章

  1. cb34a_c++_STL_算法_查找算法_(7)_lower_bound

    cb34a_c++_STL_算法_查找算法_(7)_lower_bound//针对已序区间的查找算法,如set,multiset关联容器-自动排序lower_bound()--第一个可能的位置uppe ...

  2. cb33a_c++_STL_算法_查找算法_(6)binary_search_includes

    cb33a_c++_STL_算法_查找算法_(6)binary_search_includes//针对已序区间的查找算法,如set,multiset关联容器-自动排序binary_search(b,e ...

  3. cb32a_c++_STL_算法_查找算法_(5)adjacent_find

    cb32a_c++_STL_算法_查找算法_(5)adjacent_findadjacent_find(b,e),b,begin(),e,end()adjacent_find(b,e,p),p-par ...

  4. cb31a_c++_STL_算法_查找算法_(4)find_first_of

    cb31a_c++_STL_算法_查找算法_(4)find_first_offind_first_of(b,e,sb,se),sb,second begin, se,second end();find ...

  5. cb30a_c++_STL_算法_查找算法_(3)search_find_end

    cb30a_c++_STL_算法_查找算法_(3)search_find_endsearch()pos = search(ideq.begin(), ideq.end(), ilist.begin() ...

  6. cb28a_c++_STL_算法_查找算法_(1)find_find_if

    cb28a_c++_STL_算法_查找算法_(1)find_find_iffind() //线性查找,比较慢.pos1 = find(ilist.begin(), ilist.end(), 5);fi ...

  7. STL_算法_查找算法(lower_bound、upper_bound、equal_range)

    C++ Primer 学习中. .. 简单记录下我的学习过程 (代码为主) //全部容器适用(O(log(n)))    已序区间查找算法 lower_bound()        //找第一个符合的 ...

  8. STL_算法_查找算法(find、find_if)

    C++ Primer 学习中. .. 简单记录下我的学习过程 (代码为主) find . find_if /**********************线性查找O(n) find(); find_if ...

  9. STL_算法_查找算法(binary_search、includes)

    C++ Primer 学习中.. . 简单记录下我的学习过程 (代码为主) 全部容器适用(O(log(n)))     已序区间查找算法 binary_search             //二分查 ...

随机推荐

  1. shiro的使用详解~

    在家无聊复习一下shiro 打开了之前的项目,由于lombok插件安装不了,不知道idea抽什么风所以get,set方法报错了,将就一下 只看shiro的使用,配置在shiro分类中有 登录方法 pa ...

  2. Spring MVC基于注解@Controller和@RequestMapping开发的一个例子

    1.创建web项目 2.在springmvc的配置文件中指定注解驱动,配置扫描器 在 Spring MVC 中使用扫描机制找到应用中所有基于注解的控制器类,所以,为了让控制器类被 Spring MVC ...

  3. 强力解决使用node版本管理工具 NVM 出现的问题(找不到 node,或者找不到 npm)

    nvm是好用的Nodejs版本管理工具, 通过它可以方便地在本地调换Node版本. 2020-05-28 当前长期稳定版12.17.0,于是 nvm install 12.17.0 然后C:/nvm/ ...

  4. [PHP学习教程 - 类库]001.全局唯一ID(GUID)

    GUID: 即Globally Unique Identifier(全球唯一标识符) 也称作 UUID(Universally Unique IDentifier) . GUID 是一个通过特定算法产 ...

  5. html5学习之路_003

    html布局 使用<div>元素布局 使用<table>元素布局 <div>元素布局 <!DOCTYPE html> <html> < ...

  6. [Objective-C] 010_Foundation框架之NSSet与NSMutableSet

    在Cocoa Foundation中的NSSet和NSMutableSet ,和NSArray功能性质一样,用于存储对象属于集合.但是NSSet和NSMutableSet是无序的, 保证数据的唯一性, ...

  7. Bank2

    Account: package banking2; //账户 public class Account { private double balance;// 账户余额 public Account ...

  8. Gauge框架在JS中的简单应用

    gauge框架简介 Gauge是一个轻量级的跨平台测试自动化工具. gauge安装[Win10 64位下测试] [百度网盘链接]https://pan.baidu.com/s/1bidE34gLLrS ...

  9. 13 . Python3之并发编程

    什么是操作系统? 为什么要有操作系统? 现代的计算机系统主要是由一个或者多个处理器,主存,硬盘,键盘,鼠标,显示器,打印机,网络接口及其他输入输出设备组成. 一般而言,现代计算机系统是一个复杂的系统. ...

  10. jQuery-语言基础整理

    jQuery是js的一个类库,主要封装的是js中DOM操作部分,使用和原生js一样 1.需要先引入页面才可以使用 代码引入:<script src='jquery.js'></scr ...