From 129abf6113a48f928b5b8b47a54ff60184947cea Mon Sep 17 00:00:00 2001 From: Ankush Agarwal Date: Mon, 22 Oct 2018 08:44:21 -0700 Subject: [PATCH 1/2] Add comments about unordered_map and unordered_set --- c++.html.markdown | 2 ++ 1 file changed, 2 insertions(+) diff --git a/c++.html.markdown b/c++.html.markdown index 8be5a278..f1ad0790 100644 --- a/c++.html.markdown +++ b/c++.html.markdown @@ -1027,6 +1027,7 @@ for (it = my_vector.begin(); it != my_vector.end(); ++it) { // Set // Sets are containers that store unique elements following a specific order. +// For hash sets, use unordered_set. They are more effecient but do not preserve order. // Set is a very useful container to store unique values in sorted order // without any other functions or code. @@ -1061,6 +1062,7 @@ cout << ST.size(); // will print the size of set ST // Map // Maps store elements formed by a combination of a key value // and a mapped value, following a specific order. +// For hash maps, use unordered_map. They are more effecient but do not preserve order. #include map mymap; // Will initialize the map with key as char and value as int From 2e6208c754becae469c4056ac9ecdea40f490064 Mon Sep 17 00:00:00 2001 From: Ankush Agarwal Date: Mon, 22 Oct 2018 09:12:29 -0700 Subject: [PATCH 2/2] Update comments --- c++.html.markdown | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/c++.html.markdown b/c++.html.markdown index f1ad0790..225472cb 100644 --- a/c++.html.markdown +++ b/c++.html.markdown @@ -1027,7 +1027,6 @@ for (it = my_vector.begin(); it != my_vector.end(); ++it) { // Set // Sets are containers that store unique elements following a specific order. -// For hash sets, use unordered_set. They are more effecient but do not preserve order. // Set is a very useful container to store unique values in sorted order // without any other functions or code. @@ -1058,11 +1057,12 @@ cout << ST.size(); // will print the size of set ST // Output: 0 // NOTE: for duplicate elements we can use multiset +// NOTE: For hash sets, use unordered_set. They are more effecient but +// do not preserve order. unordered_set is available since C++11 // Map // Maps store elements formed by a combination of a key value // and a mapped value, following a specific order. -// For hash maps, use unordered_map. They are more effecient but do not preserve order. #include map mymap; // Will initialize the map with key as char and value as int @@ -1086,6 +1086,8 @@ cout << it->second; // Output: 26 +// NOTE: For hash maps, use unordered_map. They are more effecient but do +// not preserve order. unordered_map is available since C++11. /////////////////////////////////// // Logical and Bitwise operators