Advertisement
vaibhav1906

Unordered_set , Ordered set

Nov 20th, 2021
1,587
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     unordered_set <int> s; //you can use unordered_multiset if you want to store any int more than once
  7.     //set<int>s ==> arrenges values in asending order
  8.     s.insert(5);
  9.     s.insert(8);
  10.     s.insert(3);
  11.     s.insert(8);
  12.    
  13.     //s.begin() ==>Address of the first element of unordered_set
  14.     //s.end()  ==> Address of last element+one
  15.     //s.end()-1 ==> Address of last element
  16.    
  17.     int a = 2;
  18.    
  19.     if(s.find(a) == s.end()){
  20.         cout<<"Given int is not present"<<endl;
  21.     }
  22.     else{
  23.         cout<<"Yeah I am here"<<endl;
  24.     }
  25.    
  26.     unordered_set <int> :: iterator it;
  27.    
  28.     //s.erase(8);
  29.    
  30.     for(it = s.begin(); it!=s.end(); it++){
  31.         cout<<*it<<" ";
  32.     }
  33.    
  34.    
  35.    
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement