-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from NicolaBernini/datastructures_cpp_20190410…
…_1232_1 Datastructures cpp 20190410 1232 1
- Loading branch information
Showing
2 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* @brief Verify both the unordered_set and set iterability | ||
* | ||
* - In addition to the lookup semantic they also provide an iterable semantic | ||
* - In case of set, it is ordered according to the operator< () definition hence by default it is ascending | ||
* - In case of unordered_set there is no order guarantee | ||
*/ | ||
|
||
#include <iostream> | ||
#include <unordered_set> | ||
#include <set> | ||
|
||
#include <vector> | ||
#include <string> | ||
|
||
using namespace std; | ||
|
||
template <typename T> | ||
string to_str(const T& a) | ||
{ | ||
string res=""; | ||
for(auto i=a.begin(); i!=a.end(); ++i) res += to_string(*i) + " "; | ||
return res; | ||
} | ||
|
||
int main() { | ||
// your code goes here | ||
unordered_set<int> a; | ||
set<int> c; | ||
|
||
const vector<int> t({11, 5, 22, 6, 90}); | ||
for(const auto& e : t) | ||
{ | ||
a.insert(e); | ||
c.insert(e); | ||
} | ||
|
||
|
||
cout << "A = " << to_str(a) << endl; | ||
cout << "C = " << to_str(c) << endl; | ||
|
||
|
||
return 0; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
# Overview | ||
|
||
Some Exercises related to `unordered_map` `unordered_set` `map` `set` elements | ||
|
||
# Set and Map access interface | ||
|
||
Iterability Access | ||
|
||
- Verify both the `unordered_set` and `set` provide in addition to the lookup semantic also the iterable semantic | ||
- Verify in case of `set` the order is defined by the `operator< ()` definition hence it is ascending and in case of `unordered_set` there is no order guarantee | ||
- [Sol](map_set_iterate1.cpp) | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
Work in progress | ||
|