| 1 | #include<bits/stdc++.h> |
| 2 | using namespace std; |
| 3 | int main(){ |
| 4 | |
| 5 | //Set is a container which keeps a unique copy of every element in sorted order. |
| 6 | |
| 7 | set<int>s; //empty set of integers |
| 8 | //set<string>s; //empty set of strings |
| 9 | |
| 10 | s.insert(20); |
| 11 | s.insert(30); |
| 12 | cout<<s.count(10)<<endl; |
| 13 | cout<<s.count(20)<<endl; |
| 14 | cout<<s.count(40)<<endl; |
| 15 | cout<<s.count(30)<<endl; |
| 16 | cout<<s.count(110)<<endl; |
| 17 | |
| 18 | s.erase(10); |
| 19 | cout<<s.count(10)<<endl; |
| 20 | /* IMPORTANT FUNCTIONS |
| 21 | s.insert(x); - insert the value x into set, do nothing if already present. O(log N) |
| 22 | s.erase(x); - erase the value x from set if present. O(log N) |
| 23 | s.count(x); -returns 0 if x ain't in the set and 1 if it's there. O(log N) |
| 24 | s.clear()- erase all elements. O(N) |
| 25 | s.size()- returns the current size of the set. O(1) |
| 26 | |
| 27 | WRONG: cout<<s[0]; //operator doesnt work with sets |
| 28 | */ |
| 29 | |
| 30 | } |