From 0e88baab1a3a7689f6ea196999a076e7f57fa2f3 Mon Sep 17 00:00:00 2001 From: parthsaboo Date: Mon, 3 Oct 2022 03:15:46 +0530 Subject: [PATCH 1/2] Added emplace_hint.md in unordered_map directory --- unordered_map/emplace_hint.md | 40 +++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 unordered_map/emplace_hint.md diff --git a/unordered_map/emplace_hint.md b/unordered_map/emplace_hint.md new file mode 100644 index 00000000..f4fbd47f --- /dev/null +++ b/unordered_map/emplace_hint.md @@ -0,0 +1,40 @@ +# emplace_hint + +**Description :** + * Inserts the key and its element in the unordered_map with a given hint. The hint provided does not affect the position to be entered. It inserts in the same order which is followed by the container. + * Only inserts unique key and avoids creating object for exisitng key. + +**Example** : + +```cpp +#include +#include +#include + +using namespace std; + + +int main() { + + // initialize unordered_map container + unordered_map mp; + + // inserting elements in random order + mp.emplace_hint(mp.begin(),3,"three"); + mp.emplace_hint(mp.begin(),1,"one"); + mp.emplace_hint(mp.begin(),2,"two"); + + + // printing the map elements + cout<<"The unordered_map elements are:"<first<<"\t"; + cout<second< Date: Mon, 3 Oct 2022 03:33:50 +0530 Subject: [PATCH 2/2] Added emplace_hint.md file in unordered_map directory --- unordered_map/emplace_hint.md | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/unordered_map/emplace_hint.md b/unordered_map/emplace_hint.md index f4fbd47f..4e9ceefe 100644 --- a/unordered_map/emplace_hint.md +++ b/unordered_map/emplace_hint.md @@ -7,34 +7,38 @@ **Example** : ```cpp +/* + Author : parth_s + Date : 03/10/2022 + Time : 02:12 + Description : Implementation of emplace_hint method in an unordered_map in C++ +*/ + #include #include #include -using namespace std; - - int main() { // initialize unordered_map container - unordered_map mp; + std::unordered_map mp; // inserting elements in random order - mp.emplace_hint(mp.begin(),3,"three"); - mp.emplace_hint(mp.begin(),1,"one"); - mp.emplace_hint(mp.begin(),2,"two"); + mp.emplace_hint(mp.begin(), 3, "three"); + mp.emplace_hint(mp.begin(), 1, "one"); + mp.emplace_hint(mp.begin(), 2, "two"); // printing the map elements - cout<<"The unordered_map elements are:"<first<<"\t"; - cout<second<first<<"\t"; + std::cout<second<<"\n"; } return 1; } ``` -**[Run Code](https://rextester.com/QJT17849)** +**[Run Code](https://rextester.com/AULM68896)**