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");

}

相关推荐
CoovallyAIHub16 小时前
YOLOv12之后,AI在火场如何进化?2025最后一篇YOLO论文揭示:要在浓烟中看见关键,仅靠注意力还不够
深度学习·算法·计算机视觉
梭七y16 小时前
【力扣hot100题】(121)反转链表
算法·leetcode·链表
qq_4335545416 小时前
C++字符串hash
c++·算法·哈希算法
无限进步_16 小时前
【C语言】堆(Heap)的数据结构与实现:从构建到应用
c语言·数据结构·c++·后端·其他·算法·visual studio
再难也得平16 小时前
两数之和和字母异位词分组
数据结构·算法
shizhenshide17 小时前
极速响应:平均破解速度<3秒的验证码服务,为抢购爬虫而生
算法
AD钙奶-lalala17 小时前
leetcode核心母题总结
算法·leetcode·职场和发展
努力学算法的蒟蒻17 小时前
day53(1.4)——leetcode面试经典150
算法·leetcode·面试
leiming617 小时前
c++ transform算法
开发语言·c++·算法