Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <list>
- #include <set>
- #include <iterator>
- #include <algorithm>
- void sets();
- void lists();
- int main()
- {
- using namespace std;
- cout << "Listy: " << endl;
- lists();
- cout << endl;
- cout << "Sety:" << endl;
- sets();
- return 0;
- }
- void sets()
- {
- using namespace std;
- set<string> A{"bufon", "studenci", "dla", "trudny", "potrafi", "dla"};
- set<string> B{"metal", "dowolny", "jedzenie", "elegancki", "dostarczyc", "dla"};
- std::ostream_iterator<string, char> out(std::cout, " ");
- cout << "Set A: ";
- std::copy(A.begin(), A.end(), out);
- cout << endl;
- cout << "Set B: ";
- std::copy(B.begin(), B.end(), out);
- cout << endl;
- cout << "Suma A i B: ";
- set_union(A.begin(), A.end(), B.begin(), B.end(), out);
- cout << endl;
- cout << "Przeciecie A i B: ";
- set_intersection(A.begin(), A.end(), B.begin(), B.end(), out);
- cout << endl;
- cout << "Roznica A - B: ";
- set_difference(A.begin(), A.end(), B.begin(), B.end(), out);
- cout << endl;
- cout << "Roznica B - A: ";
- set_difference(B.begin(), B.end(), A.begin(), A.end(), out);
- cout << endl;
- set<string> C;
- set_union(A.begin(), A.end(), B.begin(), B.end(), insert_iterator<decltype(C)>(C, C.begin()));
- cout << "Set C: ";
- std::copy(C.begin(), C.end(), out);
- cout << endl;
- C.insert("brudny");
- cout << "Set C po insert: ";
- std::copy(C.begin(), C.end(), out);
- cout << endl;
- cout << "Wyswietlenie zakresu: ";
- std::copy(C.lower_bound("duch"), C.upper_bound("monstrum"), out);
- cout << endl;
- }
- void lists()
- {
- using namespace std;
- list<int> one(5, 2);
- int stuff[5] = {1, 2, 4, 8, 6};
- list<int> two;
- two.insert(two.begin(), stuff, stuff+5);
- int more[6] = {6, 4, 2, 4, 6, 5};
- list<int> three(two);
- ostream_iterator<int, char> out(cout, " ");
- cout << "List one: ";
- copy(one.begin(), one.end(), out);
- cout << endl <<"List two: ";
- copy(two.begin(), two.end(), out);
- cout << endl << "List three: ";
- copy(three.begin(), three.end(), out);
- three.remove(2);
- cout << endl << "Three without twos: ";
- copy(three.begin(), three.end(), out);
- three.splice(three.begin(), one);
- cout << endl << "Three after splice: ";
- copy(three.begin(), three.end(), out);
- cout << endl << "List one: ";
- copy(one.begin(), one.end(), out);
- three.unique();
- cout << endl << "Three after unique: ";
- copy(three.begin(), three.end(), out);
- three.sort();
- three.unique();
- cout << endl << "Three after sort and unique: ";
- copy(three.begin(), three.end(), out);
- two.sort();
- three.merge(two);
- cout << endl << "Two sorted and pasted into three: ";
- copy(three.begin(), three.end(), out);
- three.unique();
- cout << endl << "Three after unique: ";
- copy(three.begin(), three.end(), out);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement