c++ find 算法

#include <iostream>

#include <string>

#include <fstream>

#include <vector>

#include <algorithm>

#include <deque>

#include <stack>

#include <queue>

#include <list>

#include <set>

#include <map>

#include <functional>

using namespace std;

void test01()

{

vector<int> v1;

for(int i = 0; i < 10; ++i)

{

v1.push_back(i);

}

vector<int>::iterator it = find(v1.begin(), v1.end(), 5);

if(it != v1.end())

{

cout << "find" << *it << endl;

}

else

{

cout << "dont" << 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_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> v1;

Person p1("xiaoming", 10);

Person p2("xiaohong", 20);

Person p3("xiaolan", 30);

Person p4("xiaofang", 40);

v1.push_back(p1);

v1.push_back(p2);

v1.push_back(p3);

v1.push_back(p4);

Person p5("xiaofang", 40);

vector<Person>::iterator it = find(v1.begin(), v1.end(), p5);

if(it == v1.end())

{

cout << "dont" << endl;

}

else

{

cout << "find" << endl;

}

}

int main()

{

//test01();

test02();

return 0;

system("pause");

}

相关推荐
All for pursuit.14 分钟前
【栈-5】84.柱状图中最大的矩形
数据结构·c++·算法·leetcode
wzdark21 分钟前
数据压缩算法的时间复杂度与压缩率权衡4
算法
小陈phd39 分钟前
深入理解agent学习笔记(一)——现代agent介绍
人工智能·算法
晴天的雨.9924 小时前
【C++算法】和为s的两个数
开发语言·数据结构·c++·算法
aramae10 小时前
MySQL复合查询(8)
java·c语言·开发语言·后端·算法
荆棘鸟智能11 小时前
城市感知设备怎么统一接入?从多协议网关到设备模型的中间件架构设计
人工智能·算法·边缘计算
INGNIGHT15 小时前
270 · 电话号码的字母组合II(Trie)
linux·算法
2401_8390805415 小时前
C++常见八股
数据结构·c++·算法
青山是哪个青山16 小时前
LeetCode 188:买卖股票的最佳时机 IV
算法
mikuyyds16 小时前
geo-toolbox 插件算法解析:RUSLE 与 MUSLE 的工程化落地
算法·rust·gis