Advertisement
DiaxPlayer

Untitled

Feb 21st, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.72 KB | None | 0 0
  1. #include <iostream>
  2. #include <list>
  3. #include <set>
  4. #include <iterator>
  5. #include <algorithm>
  6.  
  7. void sets();
  8. void lists();
  9.  
  10. int main()
  11. {
  12.     using namespace std;
  13.     cout << "Listy: " << endl;
  14.     lists();
  15.     cout << endl;
  16.     cout << "Sety:" << endl;
  17.     sets();
  18.    
  19.     return 0;
  20. }
  21.  
  22. void sets()
  23. {
  24.     using namespace std;
  25.     set<string> A{"bufon", "studenci", "dla", "trudny", "potrafi", "dla"};
  26.     set<string> B{"metal", "dowolny", "jedzenie", "elegancki", "dostarczyc", "dla"};
  27.     std::ostream_iterator<string, char> out(std::cout, " ");
  28.  
  29.     cout << "Set A: ";
  30.     std::copy(A.begin(), A.end(), out);
  31.     cout << endl;
  32.     cout << "Set B: ";
  33.     std::copy(B.begin(), B.end(), out);
  34.     cout << endl;
  35.  
  36.     cout << "Suma A i B: ";
  37.     set_union(A.begin(), A.end(), B.begin(), B.end(), out);
  38.     cout << endl;
  39.  
  40.     cout << "Przeciecie A i B: ";
  41.     set_intersection(A.begin(), A.end(), B.begin(), B.end(), out);
  42.     cout << endl;
  43.  
  44.     cout << "Roznica A - B: ";
  45.     set_difference(A.begin(), A.end(), B.begin(), B.end(), out);
  46.     cout << endl;
  47.  
  48.     cout << "Roznica B - A: ";
  49.     set_difference(B.begin(), B.end(), A.begin(), A.end(), out);
  50.     cout << endl;
  51.  
  52.     set<string> C;
  53.     set_union(A.begin(), A.end(), B.begin(), B.end(), insert_iterator<decltype(C)>(C, C.begin()));
  54.    
  55.     cout << "Set C: ";
  56.     std::copy(C.begin(), C.end(), out);
  57.     cout << endl;
  58.  
  59.     C.insert("brudny");
  60.    
  61.     cout << "Set C po insert: ";
  62.     std::copy(C.begin(), C.end(), out);
  63.     cout << endl;
  64.  
  65.     cout << "Wyswietlenie zakresu: ";
  66.     std::copy(C.lower_bound("duch"), C.upper_bound("monstrum"), out);
  67.     cout << endl;
  68. }
  69.  
  70. void lists()
  71. {
  72.     using namespace std;
  73.     list<int> one(5, 2);
  74.     int stuff[5] = {1, 2, 4, 8, 6};
  75.     list<int> two;
  76.     two.insert(two.begin(), stuff, stuff+5);
  77.     int more[6] = {6, 4, 2, 4, 6, 5};
  78.     list<int> three(two);
  79.     ostream_iterator<int, char> out(cout, " ");
  80.  
  81.     cout << "List one: ";
  82.     copy(one.begin(), one.end(), out);
  83.     cout << endl <<"List two: ";
  84.     copy(two.begin(), two.end(), out);
  85.     cout << endl << "List three: ";
  86.     copy(three.begin(), three.end(), out);
  87.  
  88.     three.remove(2);
  89.     cout << endl << "Three without twos: ";
  90.     copy(three.begin(), three.end(), out);
  91.  
  92.     three.splice(three.begin(), one);
  93.     cout << endl << "Three after splice: ";
  94.     copy(three.begin(), three.end(), out);
  95.     cout << endl << "List one: ";
  96.     copy(one.begin(), one.end(), out);
  97.  
  98.     three.unique();
  99.     cout << endl << "Three after unique: ";
  100.     copy(three.begin(), three.end(), out);
  101.  
  102.     three.sort();
  103.     three.unique();
  104.     cout << endl << "Three after sort and unique: ";
  105.     copy(three.begin(), three.end(), out);
  106.  
  107.     two.sort();
  108.     three.merge(two);
  109.     cout << endl << "Two sorted and pasted into three: ";
  110.     copy(three.begin(), three.end(), out);
  111.  
  112.     three.unique();
  113.     cout << endl << "Three after unique: ";
  114.     copy(three.begin(), three.end(), out); 
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement