算法简介:
1.find //查找元素
2.find_if //按条件查找元素
3.adjacent_find //查找相邻重复元素
4.binary_search //二分查找法 存在返回真 否则假
5.count //统计元素个数
6.count_if //按条件统计元素个数
1.find
功能描述
查找指定元素,找到返回指定元素的迭代器,找不到返回结束迭代器end()
函数原型:
find(iterator beg, iterator end, value);
// 按值查找元素,找到返回指定位置迭代器,找不到返回结束迭代器位置
// beg 开始选代器
// end 结束选代器
// value 查找的元素
//查找 内置数据类型
//查找 容器中 是否有5个这个元素
vector<int>::iterator it=find(v.begin(), v.end(), 5);
if (it == v.end())
{}
class Person
{
public:
Person(string name, int age)
{
this->m_Name = name;
this->m_Age = age;
}
//重载 == 底层find知道如何对比person数据类型
bool operator == (const Person&p)