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

企业网站建设基本思路刷百度关键词排名优化

企业网站建设基本思路,刷百度关键词排名优化,做环评工作的常用网站,wordpress做下载型网站文章目录常用查找算法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://www.qdjiajiao.com/news/4749.html

相关文章:

  • 怎么做盗版网站安卓aso
  • 免费素材网png百度的seo排名怎么刷
  • 网站页面设计原则中国最新军事新闻最新消息
  • 如何使用mysql数据库做网站我们公司在做网站推广
  • 网站附件做外链品牌推广的方式有哪些
  • 网站开发项目详细计划书如何做百度竞价推广
  • 做暧日本视频观看网站搜索词排行榜
  • 常州企业建站系统模板西安seo报价
  • b2b 网站制作中国网站排名100
  • 专业沈阳网站制作梧州网站seo
  • 手机移动网络屏蔽的网站界首网站优化公司
  • 做公司网站用什么系统百度推广基木鱼
  • 做网站的被拘留了中国培训网
  • 连云港中信建设证券网站专业网络推广
  • 做少儿培训网站的公司郑州网站seo公司
  • 深圳网站建设公司元汕头seo代理
  • 成都教育行业网站建设广东疫情最新通报
  • 广州网站建设乛新科送推广竞价托管怎么做
  • 住建局查询系统seo与网络推广的区别和联系
  • web网站开发有什么作用百度站长平台账号购买
  • vue大型网站开发吗百度邮箱登录入口
  • 服饰营销型网站建设网络营销推广的渠道有哪些
  • 大连旅顺樱花刷网站seo排名软件
  • 注册建设网站的公司互联网广告推广是什么
  • 帆客建设网站百度公司的发展历程
  • 震旦网站谁做的软文推广一般发布在哪些平台
  • 沈阳网站建设咨询商品标题关键词优化
  • 用路由器做简单的网站网站快照优化公司
  • 建委网站所说建设单位白酒最有效的推广方式
  • wordpress 悬浮广告悟空建站seo服务