Advertisement
bogolyubskiyalexey

Untitled

Jan 29th, 2021
713
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.26 KB | None | 0 0
  1. #include <iostream>
  2. #include <chrono>
  3. #include <random>
  4. #include <unordered_set>
  5. #include <set>
  6. #include <map>
  7. #include <unordered_map>
  8.  
  9.  
  10. int main() {
  11.     // set : store only keys
  12.     std::set<int> a;     // unique keys, sorted
  13.     std::multiset<int> b; // dublicated keys, sorted
  14.     std::unordered_set<int> c; // unique keys, not sorted, faster then std::set
  15.     std::unordered_multiset<int> d; // dublicated keys, not sorted, faster then std::multiset
  16.  
  17.     // associative array: key -> value
  18.     std::map<int, double> m; // unique keys, sorted
  19.     std::unordered_map<int, double> z; // unique keys, not sorted, faster then std::map
  20.  
  21.     //                        map/set         unordered_{map/set}
  22.     //insert/erase/search   O(logN)          O(1)
  23.  
  24.     for (int i = 0; i < 20; ++i) {
  25.         b.insert(i);
  26.         b.insert(i);
  27.     }
  28.     std::multiset<int>::iterator it = b.find(100);
  29.     if (it != b.end()) {
  30.         std::cout << "found " << (*it) <<  std::endl;
  31.         b.erase(it); // must be valid
  32.     } else {
  33.         std::cout << "not found" << std::endl;
  34.     }
  35.     b.erase(100); // may be not exists
  36.  
  37.    
  38.     if (b.count(10)) {
  39.  
  40.     }
  41.  
  42.     for (auto x : b) {
  43.         std::cout << x << " ";
  44.     }
  45.     std::cout << std::endl;
  46.  
  47. }
  48.  
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement