C++ //常用算法 adjacent_find //查找相邻的重复元素

 1 //常用算法 adjacent_find
 2 //查找相邻的重复元素
 3 #include<iostream>
 4 #include<string>
 5 #include<algorithm>
 6 #include<vector>
 7 
 8 using namespace std;
 9 
10 void test01()
11 {
12     vector<int>v;
13 
14     v.push_back(1);
15     v.push_back(2);
16     v.push_back(2);
17     v.push_back(1);
18     v.push_back(3);
19     v.push_back(3);
20     vector<int>::iterator it = adjacent_find(v.begin(), v.end());
21 
22     if (it == v.end())
23     {
24         cout << "未找到!" << endl;
25     }
26 
27     else
28     {
29         cout << "找到了!" << *it << endl;
30     }
31 
32 
33 }
34 
35 
36 
37 int  main()
38 {
39     test01();
40 
41     system("pause");
42     return 0; 
43 }

 

posted on 2021-08-18 10:46  Bytezero!  阅读(76)  评论(0编辑  收藏  举报