1.功能:查找相邻重复元素
2.函数原型
- adjacent_find(iterator beg, iterator end)
- 查找相邻重复元素,返回相邻元素的第一个位置的迭代器
- beg: 开始迭代器
- end: 结束迭代器
#include<iostream> #include<vector> #include<string> #include<algorithm> using namespace std; void test1() { vector<int> v; v.push_back(0); v.push_back(2); v.push_back(0); v.push_back(3); v.push_back(1); v.push_back(4); v.push_back(8); v.push_back(8); vector<int>::iterator pos = adjacent_find(v.begin(),v.end()); if (pos == v.end()) cout << "未找到!" << endl; else cout << "找到:" << *pos << endl; // 8 } int main() { test1(); return 0; }