unordered_map find in C++ STL
Last Updated :
24 Dec, 2018
find function in C++ is used to search for a specific key in an unordered map.
Syntax
unordered_map.find(key);
Parameters: It takes the key as a parameter.
Return values: If the given key exists in unordered_map it returns an iterator to that element otherwise it returns the end of the map iterator.
Below program illustrate the working of find function:
#include <bits/stdc++.h>
using namespace std;
int main()
{
unordered_map< int , bool > um;
um[12] = true ;
um[6789] = false ;
um[456] = true ;
if (um.find(23) == um.end())
cout << "Element Not Present\n" ;
else
cout << "Element Present\n" ;
if (um.find(12) == um.end())
cout << "Element Not Present\n" ;
else
cout << "Element Present\n" ;
return 0;
}
|
Output:
Element Not Present
Element Present
Time Complexity : O(1) on average.
Share your thoughts in the comments
Please Login to comment...