-
Notifications
You must be signed in to change notification settings - Fork 2
/
53.cpp
35 lines (30 loc) · 939 Bytes
/
53.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include<iostream>
#include<algorithm>
#include<vector>
int main()
{
//program to get to know the use of the functions:
//1. adjacent_find() : finds you the matching elements and returns an iterator to it. If the element is not found then iterator to end is returned
//initializing a vector
std::vector<int> v = {23,12,45,12,56,3};
std::vector<int>::iterator p = v.begin();
std::cout<<"Vector v : ";
while(p!=v.end())
{
std::cout<<*p<<" ";
p++;
}
std::cout<<std::endl;
std::cout<<"Size of the vector : "<<v.size()<<std::endl;
//finding an adjacent element
if(*std::adjacent_find(v.begin(),v.end()-1)!=*v.end())
{
std::cout<<"Yes adjacent element found\n";
std::cout<<*std::adjacent_find(v.begin(),v.begin()+3)<<std::endl;
}
else
{
std::cout<<"Vector does not contain any similar elements!"<<std::endl;
}
return 0;
}