Last active
November 22, 2018 16:30
-
-
Save Fohlen/1e65bf9f7f13fdce910280d0e7bac4ee to your computer and use it in GitHub Desktop.
Container fun
This file contains hidden or 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
#include <algorithm> | |
#include <list> | |
#include <string> | |
#include <iostream> | |
using namespace std; | |
template <typename T> | |
void print_list(list<T> l) { | |
for (auto e: l) | |
{ | |
cout << to_string(e) << endl; | |
} | |
} | |
int main(int argc, char* argv[]) { | |
list<unsigned int> container; | |
auto a = container; | |
auto b = container; | |
a = {1, 2, 3}; | |
b = {1, 2, 3, 4}; | |
if (a > b) | |
{ | |
cout << "a is real superset of b" << endl; | |
} | |
if (a >= b) | |
{ | |
cout << "a is superset of b" << endl; | |
} | |
if (a <= b) { | |
cout << "b is superset of a" << endl; | |
} | |
if (a < b) { | |
cout << "b is real superset of a" << endl; | |
} | |
auto intersect = container; | |
set_intersection(a.begin(), a.end(), b.begin(), b.end(), back_inserter(intersect)); | |
cout << "elements in intersection:" << endl; | |
print_list(intersect); | |
auto difference = container; | |
set_difference(b.begin(), b.end(), a.begin(), a.end(), back_inserter(difference)); | |
cout << "elements in diff:" << endl; | |
print_list(difference); | |
auto un = container; | |
cout << "elements in union:" << endl; | |
set_union(a.begin(), a.end(), b.begin(), b.end(), back_inserter(un)); | |
print_list(un); | |
auto min = min_element(un.begin(), un.end()); | |
cout << "the minimum element of a and b is " << to_string(*min) << endl; | |
auto max = max_element(un.begin(), un.end()); | |
cout << "the maximum element of a and b is " << to_string(*max) << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment