Skip to content

Commit

Permalink
Merge pull request #11 from NicolaBernini/datastructures_cpp_20190410…
Browse files Browse the repository at this point in the history
…_1232_1

Datastructures cpp 20190410 1232 1
  • Loading branch information
NicolaBernini authored Apr 10, 2019
2 parents 40f9bdb + 948c24f commit cefd772
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
55 changes: 55 additions & 0 deletions data_structure/map_set/map_set_iterate1.cpp
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;
}











21 changes: 21 additions & 0 deletions data_structure/map_set/readme.md
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

0 comments on commit cefd772

Please sign in to comment.