C++ Standard Library C++ STL Library

C++ unordered_multiset - find() Function



The C++ unordered_multiset::find function is used to search the container for an element equivalent to the specified value and returns the iterator to it if found, else returns the iterator to unordered_multiset::end.

Syntax

const_iterator find (const key_type& k) const;
iterator find (const key_type& k);

Parameters

k Specify value to search for.

Return Value

An iterator to the element if k is found, or unordered_multiset::end if k is not found.

Time Complexity

Average case: Constant i.e, Θ(1).
Worst case: Linear i.e, Θ(n).

Example:

In the example below, the unordered_multiset::find function is used to find the specified element in uMSet.

#include <iostream>
#include <unordered_set>
using namespace std;
 
int main (){
  unordered_multiset<int> uMSet{55, 25, 128, 25, 72};
  unordered_multiset<int>::iterator it;

  it = uMSet.find(25);
  uMSet.erase(it);

  cout<<"uMSet contains: ";
  for(it = uMSet.begin(); it != uMSet.end(); ++it)
    cout<<*it<<" ";

  return 0;
}

The output of the above code will be:

uMSet contains: 72 128 25 55 

❮ C++ <unordered_set> Library