C/C++ Arena

Step 3 of 6

std::set

std::set<T> holds unique values, sorted. Inserting a duplicate does nothing.

std::set<int> s = {5, 1, 5, 3};   // {1, 3, 5}
s.insert(2);
s.contains(3);                     // true (C++20)
s.count(9);                        // 0

Your turn: write std::vector<std::string> unique_sorted(const std::vector<std::string>& v) that returns the distinct strings in sorted order.

Previous: Look up without inserting Next: unordered_map