当前位置: 首页 > news >正文

网站建设视频vs品牌公关具体要做些什么

网站建设视频vs,品牌公关具体要做些什么,怎么在网站上加qq,做口碑都有哪些网站文章目录常用查找算法findfind_ifadjacent_findbinary_searchcountcount_if常用查找算法 算法简介: find//查找元素 find_if//按条件查找元素 adjacent_find//查找相邻重复元素 binary_search//二分查找法 count//统计元素个数 count_if//按条件统计元素个数find …

文章目录

  • 常用查找算法
    • find
    • find_if
    • adjacent_find
    • binary_search
    • count
    • count_if


常用查找算法

算法简介:

find//查找元素
find_if//按条件查找元素
adjacent_find//查找相邻重复元素
binary_search//二分查找法
count//统计元素个数
count_if//按条件统计元素个数

find

功能:查找指定元素,找到返回指定元素的迭代器,找不到返回结束迭代器end()。

函数原型:

find(iterator beg,iterator end,value);
//beg开始迭代器
//end结束迭代器
//value查找的元素
#include<iostream>
using namespace std;
#include<vector>//查找内置数据类型
void test01()
{vector<int>v;for (int i = 0; i < 10; i++){v.push_back(i);}//查找容器中是否有5这个元素vector<int>::iterator it = find(v.begin(), v.end(), 5);if (it == v.end()){cout << "没有找到!" << endl;}else{cout << "找到:" << *it << endl;}
}//查找自定义数据类型
class person
{
public:person(string name, int age){this->m_name = name;this->m_age = age;}//重载== 底层find知道如何对比person数据类型bool operator==(const person& p){if (this->m_name == p.m_name && this->m_age == p.m_age){return true;}else{return false;}}string m_name;int m_age;
};void test02()
{vector<person> v;//创建数据person p1("aaa", 18);person p2("bbb", 19);person p3("ccc", 20);person p4("ddd", 21);//放入到容器中v.push_back(p1);v.push_back(p2);v.push_back(p3);v.push_back(p4);//查找p2这个人是否存在vector<person>::iterator it = find(v.begin(), v.end(), p2);if (it == v.end()){cout << "没有找到" << endl;}else{cout << "找到元素 姓名:" << it->m_name << " 年龄:" << it->m_age << endl;}
}int main()
{test01();test02();system("pause");return 0;
}

find_if

功能:按条件查找元素,找到返回指定元素的迭代器,找不到返回结束迭代器位置end()。

函数原型:

find_if(iterator beg,iterator end,_Pred);
//beg开始迭代器
//end结束迭代器
//_Pred函数或者谓词(返回bool类型的仿函数)
#include<iostream>
using namespace std;
#include<vector>
#include<algorithm>
#include<string>//查找内置数据类型
class greater5
{
public:bool operator()(int val){return val > 5;}
};void test01()
{vector<int>v;for (int i = 0; i < 10; i++){v.push_back(i);}//查找容器中是否有大于5的vector<int>::iterator it = find_if(v.begin(), v.end(), greater5());if (it == v.end()){cout << "没有找到!" << endl;}else{cout << "找到大于5的数为:" << *it << endl;//6}
}//查找自定义数据类型
class person
{
public:person(string name, int age){this->m_name = name;this->m_age = age;}string m_name;int m_age;
};class greater20
{
public:bool operator()(person& p){return p.m_age > 20;}
};void test02()
{vector<person> v;//创建数据person p1("aaa", 18);person p2("bbb", 19);person p3("ccc", 20);person p4("ddd", 21);//放入到容器中v.push_back(p1);v.push_back(p2);v.push_back(p3);v.push_back(p4);//查找容器中是否有年龄大于20的vector<person>::iterator it = find_if(v.begin(), v.end(), greater20());if (it == v.end()){cout << "没有找到" << endl;}else{cout << "找到元素 姓名:" << it->m_name << " 年龄:" << it->m_age << endl;}
}int main()
{test01();test02();system("pause");return 0;
}

adjacent_find

功能:查找相邻重复元素,返回相邻元素的第一个元素的迭代器。

函数原型:

adjacent_find(iterator beg,iterator end);
//beg开始迭代器
//end结束迭代器
#include<iostream>
using namespace std;
#include<vector>
#include<algorithm>void test01()
{vector<int> v;v.push_back(0);v.push_back(2);v.push_back(3);v.push_back(0);v.push_back(2);v.push_back(1);v.push_back(1);v.push_back(4);vector<int>::iterator pos = adjacent_find(v.begin(), v.end());if (pos == v.end()){cout << "未找到相邻重复元素" << endl;}else{cout << "找到相邻重复元素:" << *pos << endl;}
}int main()
{test01();system("pause");return 0;
}

binary_search

功能:查找指定元素是否存在,查到返回true,否则返回false,二分查找法查找效率很高。

注意:在无序序列中不可用。

函数原型:

bool binary_search(iterator beg,iterator value);
//beg开始迭代器
//end结束迭代器
//value查找的元素
#include<iostream>
using namespace std;
#include<vector>
#include<algorithm>//binary_search查找元素必须是有序序列
void test01()
{vector<int> v;for (int i = 0; i < 10; i++){v.push_back(i);}v.push_back(5);//尾部插入5这个元素,变为无序序列,binary_search查找不到元素//查找容器中是否有9这个元素bool ret = binary_search(v.begin(), v.end(), 9);if (ret){cout << "找到元素" << endl;}else{cout << "未找到元素" << endl;}
}int main()
{test01();system("pause");return 0;
}

count

功能:统计元素个数。

函数原型:

count(iterator beg,iterator end,value);
//beg开始迭代器
//end结束迭代器
//value统计的元素
#include<iostream>
using namespace std;
#include<vector>
#include<algorithm>
#include<string>//统计内置数据类型
void test01()
{vector<int>v;v.push_back(1);	v.push_back(2);v.push_back(5);v.push_back(7);v.push_back(8);v.push_back(2);v.push_back(5);v.push_back(2);//统计5的个数int num = count(v.begin(), v.end(), 5);cout << "5的个数为:" << num << endl;
}//统计自定义数据类型
class person
{
public:person(string name, int age){this->m_name = name;this->m_age = age;}bool operator==(const person& p){if (this->m_age == p.m_age){return true;}else{return false;}}string m_name;int m_age;
};void test02()
{vector<person> v;//创建数据person p1("aaa", 18);person p2("bbb", 19);person p3("ccc", 18);person p4("ddd", 21);person p("ggg", 18);//放入到容器中v.push_back(p1);v.push_back(p2);v.push_back(p3);v.push_back(p4);//统计容器中与p年龄相同的人int num = count(v.begin(), v.end(), p);cout << "和ggg年龄相同的人数:" << num << endl;}int main()
{test01();test02();system("pause");return 0;
}

总结:统计自定义数据类型时,需要配合重载operator==。

count_if

功能:按提条件统计元素个数。

函数原型:

count_if(iterator beg,iterator end,_Pred);
//beg开始迭代器
//end结束迭代器
//_Pred谓词
#include<iostream>
using namespace std;
#include<vector>
#include<algorithm>
#include<string>//统计内置数据类型
class greater5
{
public:bool operator()(int val){return val > 5;}
};void test01()
{vector<int>v;v.push_back(1);v.push_back(2);v.push_back(5);v.push_back(7);v.push_back(8);v.push_back(2);v.push_back(5);v.push_back(2);//统计5的个数int num = count_if(v.begin(), v.end(), greater5());cout << "大于5的个数为:" << num << endl;
}//统计自定义数据类型
class person
{
public:person(string name, int age){this->m_name = name;this->m_age = age;}string m_name;int m_age;
};class greater20
{
public:bool operator()(const person& p){return p.m_age > 20;//如果年龄大于20返回真,否则返回假}
};void test02()
{vector<person> v;//创建数据person p1("aaa", 23);person p2("bbb", 19);person p3("ccc", 20);person p4("ddd", 21);person p("ggg", 18);//放入到容器中v.push_back(p1);v.push_back(p2);v.push_back(p3);v.push_back(p4);//统计容器中与p年龄相同的人int num = count_if(v.begin(), v.end(), greater20());cout << "年龄大于20的人数:" << num << endl;
}int main()
{test01();test02();system("pause");return 0;
}


文章转载自:
http://snooper.jqLx.cn
http://shadiness.jqLx.cn
http://bumfreezer.jqLx.cn
http://spartanize.jqLx.cn
http://librate.jqLx.cn
http://oebf.jqLx.cn
http://votable.jqLx.cn
http://cupreous.jqLx.cn
http://hognut.jqLx.cn
http://curiosity.jqLx.cn
http://lockmaster.jqLx.cn
http://innominate.jqLx.cn
http://esophageal.jqLx.cn
http://internauts.jqLx.cn
http://practical.jqLx.cn
http://jehoshaphat.jqLx.cn
http://pracharak.jqLx.cn
http://tacamahac.jqLx.cn
http://offhand.jqLx.cn
http://rancho.jqLx.cn
http://twinned.jqLx.cn
http://sticktight.jqLx.cn
http://untrod.jqLx.cn
http://encroach.jqLx.cn
http://dephlegmate.jqLx.cn
http://cienfuegos.jqLx.cn
http://ghastliness.jqLx.cn
http://cargojet.jqLx.cn
http://prole.jqLx.cn
http://lorica.jqLx.cn
http://postfactor.jqLx.cn
http://subcrust.jqLx.cn
http://stirring.jqLx.cn
http://mizzenmast.jqLx.cn
http://vexillary.jqLx.cn
http://magnetofluidmechanic.jqLx.cn
http://tutto.jqLx.cn
http://creak.jqLx.cn
http://capersome.jqLx.cn
http://restrictionist.jqLx.cn
http://disinvestment.jqLx.cn
http://catecholamine.jqLx.cn
http://dilettantism.jqLx.cn
http://eohippus.jqLx.cn
http://heterocyclic.jqLx.cn
http://sensa.jqLx.cn
http://delomorphous.jqLx.cn
http://clyde.jqLx.cn
http://shoeshine.jqLx.cn
http://gastralgic.jqLx.cn
http://intrados.jqLx.cn
http://overshot.jqLx.cn
http://magenta.jqLx.cn
http://babyless.jqLx.cn
http://lowestoft.jqLx.cn
http://quadrilled.jqLx.cn
http://garibaldist.jqLx.cn
http://fisherman.jqLx.cn
http://fatidical.jqLx.cn
http://surd.jqLx.cn
http://phthisis.jqLx.cn
http://alkalinization.jqLx.cn
http://tzarevich.jqLx.cn
http://iges.jqLx.cn
http://contaminative.jqLx.cn
http://asteria.jqLx.cn
http://thinker.jqLx.cn
http://skidder.jqLx.cn
http://designment.jqLx.cn
http://blandiloquence.jqLx.cn
http://highborn.jqLx.cn
http://incent.jqLx.cn
http://expansively.jqLx.cn
http://chickenlivered.jqLx.cn
http://skivey.jqLx.cn
http://cerate.jqLx.cn
http://tanist.jqLx.cn
http://fetwa.jqLx.cn
http://spatchcock.jqLx.cn
http://neurochemist.jqLx.cn
http://autogeneration.jqLx.cn
http://sociology.jqLx.cn
http://cucumber.jqLx.cn
http://minna.jqLx.cn
http://impart.jqLx.cn
http://nappe.jqLx.cn
http://cachinnate.jqLx.cn
http://venomous.jqLx.cn
http://cinerous.jqLx.cn
http://outmarch.jqLx.cn
http://synchronoscope.jqLx.cn
http://violoncellist.jqLx.cn
http://newswire.jqLx.cn
http://logginess.jqLx.cn
http://illuminometer.jqLx.cn
http://moisten.jqLx.cn
http://ambient.jqLx.cn
http://plowman.jqLx.cn
http://intoxicant.jqLx.cn
http://unaccepted.jqLx.cn
http://www.hrbkazy.com/news/93150.html

相关文章:

  • 广州网站排名优化服务东莞今天的最新通知
  • 滁州网站开发活动推广方案
  • 网站地图 制作工具快速优化排名公司推荐
  • 手机制作logo神器成都百度推广排名优化
  • 库存管理软件免费 哪个好唐山百度提升优化
  • 网站建设行业赚钱么免费友情链接网页
  • 潍坊定制网站搭建seo营销
  • 网站营销咨询顾问刘雯每日资讯
  • 高端的电影网站怎样才能注册自己的网站
  • 网站开发时间进度编写网页的软件
  • 遵义市做网站的地方营销型企业网站推广的方法有哪些
  • 浙江台州网站制作怎么推广自己的微信号
  • 中企动力服务怎么样如何做优化排名
  • 包头网站开发建设海外推广运营
  • 信阳制作网站ihanshi素材网
  • 网站可以有二维码吗网站描述和关键词怎么写
  • wordpress需要备案吗seo搜索引擎优化公司
  • 阳春市政府网站集约化建设谷歌广告联盟官网
  • wordpress多站点设置香飘飘奶茶
  • 如何制作网络自动优化句子的软件
  • 一般做企业网站需要什么互联网营销方式有哪些
  • 网站开发一对一搜索引擎网站排名
  • 网站建设网站维护的具体内容是什么小红书关键词优化
  • wordpress 相册广东网站seo营销
  • 可以做婚礼视频的网站热点新闻事件及观点
  • 学做西餐网站百度allin 人工智能
  • 川畅科技网站设计站内推广和站外推广的区别
  • 数字尾巴+wordpress宁波企业seo外包
  • 建筑毕业设计代做网站百度号码认证申诉平台
  • 挂甲寺网站建设宁波seo教程