emplace_hint(): This function is available in the File: unordered_set.h
Syntax:
template<class... _Args> std::unordered_set<int>::iterator std::unordered_set<int>::emplace_hint(std::unordered_set<int>::const_iterator __pos, _Args &&...__args)
This function attempts to insert an element into the unordered_set.
Parameters: Two parameters are required for this function.
__pos – An iterator that serves as a hint as to where the element should be inserted.
__args – Arguments used to generate the element to be inserted.
Returns: An iterator that points to the element with a key equivalent to the one generated from __args (may or may not be the element itself).
Note: The first parameter is only a hint and can potentially improve the performance of the insertion process.
File: unordered_set.h
Approach
C++
#include <bits/stdc++.h>using namespace std;int main(){unordered_set<int> st = {1, 4, 6, 7};int val = 5;st.emplace_hint(st.begin(), val);cout << "All elements are: ";for (auto it = st.begin(); it != st.end(); it++)cout << *it << " ";return 0;}
Output:
All elements are: 5 1 6 4 7
No comments:
Post a Comment