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

}

相关推荐
憨波个1 分钟前
【说话人日志】DOVER:diarization 输出融合算法
人工智能·算法·音频·语音识别·聚类
爱学习的张大3 分钟前
具身智能论文问答(四):pi0
人工智能·算法
上弦月-编程8 分钟前
指针编程:高效内存管理核心
java·数据结构·算法
罗超驿9 分钟前
双指针算法经典案例:LeetCode 283. 移动零(Java详解)
java·算法·leetcode
人道领域17 分钟前
【数据结构与算法分析】二叉树面试通关手册:遍历图解 · 分类对比 · 代码模板
数据结构·算法·leetcode·深度优先
水蓝烟雨18 分钟前
2901. 最长相邻不相等子序列 II
算法·leetcode
郝学胜-神的一滴22 分钟前
二分类任务核心:BCE 损失函数从原理到 PyTorch 实战
人工智能·pytorch·python·算法·机器学习·分类·数据挖掘
.54824 分钟前
Two Pointers(双指针)
java·数据结构·算法
sali-tec26 分钟前
C# 基于OpenCv的视觉工作流-章58-相机标定
图像处理·人工智能·数码相机·opencv·算法·计算机视觉
承渊政道26 分钟前
【动态规划算法】(回文串问题解题框架与经典案例)
数据结构·c++·学习·算法·leetcode·动态规划·哈希算法