Advertisement
vaibhav1906

Hashing_maps

Nov 20th, 2021
1,646
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1.  
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     unordered_map<int,string> m; // Use map<int,string> m if you want sorted by key in asanding order
  8.     m.insert({11,"Parag"});
  9.     m.insert({7,"Vishvitha"});
  10.     m[10] = "Avnish";
  11.     m.insert({7,"Sumit"});
  12.     int a = 10;
  13.     if(m.find(a)!=m.end()){
  14.         cout<<"Yes I am present"<<endl;
  15.         unordered_map<int,string> :: iterator it;
  16.         it = m.find(a);
  17.        
  18.         //auto it = m.find(a);
  19.        
  20.         cout<<"Key is : "<< it->first <<" and Value is : "<<it->second<<endl;
  21.         //cout<<"Key is : "<< m.find(a)->first <<" and Value is : "<<m.find(a)->second<<endl;
  22.     }
  23.     else{
  24.         cout<<"Hey, I am not present :("<<endl;
  25.     }
  26.    
  27.     auto it = m.begin();
  28.    
  29.     for(it; it!=m.end(); it++){
  30.         cout<<"Key : "<<it->first<<" Value : "<<it->second<<endl;
  31.     }
  32.    
  33.    
  34.    
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement