Labs ICT
โญ Pro Login

Set

C++ Set

std::set stores unique elements in sorted order. Duplicate insertions are ignored. Use insert() to add elements and find() to check if an element exists. Sets are useful when you need a collection of distinct items with fast lookups.

#include <iostream>
#include <set>

int main() {
    std::set<int> numbers;
    numbers.insert(10);
    numbers.insert(20);
    numbers.insert(10);
    std::cout << "Size: " << numbers.size() << "\n";
    auto it = numbers.find(20);
    if (it != numbers.end()) {
        std::cout << "Found: " << *it;
    }
    return 0;
}
Try it Yourself โ†’

๐Ÿงช Quick Quiz

Which container stores unique elements in sorted order?