查找算法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
posted @ 2022-07-31 13:09  thomas_blog  阅读(13)  评论(0编辑  收藏  举报