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

}

相关推荐
大江东去浪淘尽千古风流人物11 小时前
【VLN】VLN(Vision-and-Language Navigation视觉语言导航)算法本质,范式难点及解决方向(1)
人工智能·python·算法
努力学算法的蒟蒻12 小时前
day79(2.7)——leetcode面试经典150
算法·leetcode·职场和发展
2401_8414956412 小时前
【LeetCode刷题】二叉树的层序遍历
数据结构·python·算法·leetcode·二叉树··队列
AC赳赳老秦12 小时前
2026国产算力新周期:DeepSeek实战适配英伟达H200,引领大模型训练效率跃升
大数据·前端·人工智能·算法·tidb·memcache·deepseek
2401_8414956412 小时前
【LeetCode刷题】二叉树的直径
数据结构·python·算法·leetcode·二叉树··递归
budingxiaomoli12 小时前
优选算法-字符串
算法
qq74223498412 小时前
APS系统与OR-Tools完全指南:智能排产与优化算法实战解析
人工智能·算法·工业·aps·排程
A尘埃13 小时前
超市购物篮关联分析与货架优化(Apriori算法)
算法
.小墨迹13 小时前
apollo学习之借道超车的速度规划
linux·c++·学习·算法·ubuntu
不穿格子的程序员13 小时前
从零开始刷算法——贪心篇1:跳跃游戏1 + 跳跃游戏2
算法·游戏·贪心