查找算法adjacent_find相邻重复元素
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
class Print
{
public:
void operator()(int i)
{
cout << i << endl;
}
};
int main()
{
vector<int> v;
v.push_back(1);
v.push_back(3);
v.push_back(3);
v.push_back(2);
vector<int>::iterator it = adjacent_find(v.begin(), v.end());
if(it != v.end())
{
cout << "找到 " << *it << endl;
}
else
{
cout << "未找到" << endl;
}
return 0;
}
$ ./a.out
找到 3