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

}

相关推荐
CoderCodingNo7 分钟前
【GESP】C++五级练习题 luogu-P1865 A % B Problem
开发语言·c++·算法
大闲在人17 分钟前
7. 供应链与制造过程术语:“周期时间”
算法·供应链管理·智能制造·工业工程
小熳芋20 分钟前
443. 压缩字符串-python-双指针
算法
Charlie_lll30 分钟前
力扣解题-移动零
后端·算法·leetcode
chaser&upper31 分钟前
矩阵革命:在 AtomGit 解码 CANN ops-nn 如何构建 AIGC 的“线性基石”
程序人生·算法
weixin_4997715539 分钟前
C++中的组合模式
开发语言·c++·算法
iAkuya1 小时前
(leetcode)力扣100 62N皇后问题 (普通回溯(使用set存储),位运算回溯)
算法·leetcode·职场和发展
近津薪荼1 小时前
dfs专题5——(二叉搜索树中第 K 小的元素)
c++·学习·算法·深度优先
xiaoye-duck1 小时前
吃透 C++ STL list:从基础使用到特性对比,解锁链表容器高效用法
c++·算法·stl
松☆1 小时前
CANN与大模型推理:在边缘端高效运行7B参数语言模型的实践指南
人工智能·算法·语言模型