-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathAlgo2.cpp
32 lines (26 loc) · 823 Bytes
/
Algo2.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
// C++ program to demonstrate working of count()
// and find()
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main()
{
// Initializing vector with array values
int arr[] = {10, 20, 5, 23 ,42, 20, 15};
int n = sizeof(arr)/sizeof(arr[0]);
vector<int> vect(arr, arr+n);
cout << "Occurrences of 20 in vector : ";
// Counts the occurrences of 20 from 1st to
// last element
cout << count(vect.begin(), vect.end(), 20);
// find() returns iterator to last address if
// element not present
find(vect.begin(), vect.end(),5) != vect.end()?
cout << "\nElement found":
cout << "\nElement not found";
return 0;
}
Output:
Occurrences of 20 in vector: 2
Element found