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

}

相关推荐
Peregrine92 小时前
C++ - > 类和对象
java·c++·算法
Gigavision3 小时前
DEAP数据集 2026最新Transformer算法 DEAP 数据集 下载
深度学习·算法·transformer
夜之眷属3 小时前
PriorityQueue:for-each 遍历和 poll 取出,顺序一样吗?
java·服务器·数据结构·后端·算法
地平线开发者4 小时前
不是线程越多越快:用 hrt_model_exec 在 征程6M 上给 YOLOv5x 建立性能基线
算法
姜鱼问生4 小时前
fail2ban 实战:从默认配置到生产可用
后端·算法·架构
垆边人似月.4 小时前
华为题:全排列
算法·深度优先·图论
杜 硕4 小时前
快速排序详解01
数据结构·算法·排序算法
Matlab程序猿5 小时前
【MATLAB源码-第459期】基于matlab的D-H模型与阻尼最小二乘逆运动学的六自由度机械臂五次轨迹规划及动力学前馈PD控制仿真。
人工智能·算法·matlab·d-h建模·六自由度串联机械臂
信奥卷王5 小时前
[GESP202606 六级] 满二叉树
数据结构·算法
积流成海5 小时前
用代码实现哈希计算器:Web Crypto API 实战
前端·算法·哈希算法·哈希函数·盘子工具站