Tech Blogs
  • Vivek bhargav
  • Books
    • Seven Databases In Seven Weeks
      • Factors to consider
      • Genres of databases
      • Important questions
      • PostGreSQL
  • Tech
    • C++
      • Type Conversions
      • String
      • Vector
      • Set
      • Unordered Set
      • Map
      • Unordered Map
      • Queue
      • Priority Queue
      • Union find
      • Algorithms
      • Matrix to Graph
      • Trie
      • Dijkstra
      • Math
      • Utils
    • Database Transactions
      • A Simple Transaction Analysis
      • Implementation of Isolation Levels
      • Isolation Levels
      • Isolation
      • Storage Types
      • Transaction Atomicity and Durability
    • Java
      • Important Questions
      • Spring MVC
    • Program execution
      • Node.js
      • Runtimes
    • System Design
      • Basic Terminologies
      • CAP Theorem
      • Normalization of Database
      • Useful Reads
  • Personal Finance
    • Asset Classes
      • Equity instruments
      • Debt instruments
Powered by GitBook
On this page
  1. Tech
  2. C++

Unordered Set

#include <unordered_set>
  
unordered_set<int> s;                       // create an unordered_set of integers
unordered_set<int> s({4, 3, 9, 2, 0, 6});   // create an unordered_set with few initial elements
     
cout << s.size() << endl;                   // number of elements in unordered_set
s.insert(123);                              // add element to unordered_set
s.erase(444);                               // erase an element from the unordered_set
s.clear();                                  // remove all the elements from the unordered_set
        

// search for an element
if (s.find(444) != s.end()) {
    // It means 444 exists in the set
} 

// iterate over all elements
for(unordered_set<int>::iterator it = s.begin(); it != s.end(); it++) {
    cout << *it << endl;
}
PreviousSetNextMap

Last updated 2 years ago