noknow.dev
Sign inSign up
Course overview
C++ Fundamentals
0 / 39 lessons0%

Getting Started

  • Hello, World!
  • Variables and Data Types
  • Arithmetic and Operators
  • Working with std::string
  • Type Conversion and Casting

Control Flow

  • if / else if / else
  • switch / case
  • while and do-while Loops
  • for Loops
  • break, continue, and Finding Primes

Functions

  • Writing Functions
  • Pass by Value vs. Pass by Reference
  • Overloading and Default Parameters
  • Recursion

Arrays and Strings

  • C-style Arrays
  • std::vector — Dynamic Arrays
  • std::string Deep Dive
  • 2D Arrays and Matrices

Pointers and Memory

  • Memory Addresses and Pointers
  • Dynamic Memory: new and delete
  • References vs Pointers

Object-Oriented Programming

  • Classes and Objects
  • Constructors and Destructors
  • Inheritance
  • Virtual Functions and Polymorphism
  • Operator Overloading

The Standard Template Library

  • std::vector in Depth
  • std::map and std::unordered_map
  • std::set and Sorted Unique Collections
  • STL Algorithms

Templates and Generic Programming

  • Function Templates
  • Class Templates

Modern C++ (C++11/14/17)

  • auto and Range-based for
  • Lambda Functions
  • Smart Pointers
  • Move Semantics

Error Handling and Exceptions

  • try / catch / throw
  • Custom Exception Classes
  • RAII and Resource Management

std::set and Sorted Unique Collections

0m 00s

Automatic Uniqueness and Sorting

#include <set>

set<int> s = {5, 2, 8, 2, 1, 5};
// Stored as: {1, 2, 5, 8} — sorted, no duplicates

s.insert(3);            // {1,2,3,5,8}
s.erase(2);             // {1,3,5,8}
s.count(3)              // 1 (present)
s.count(99)             // 0 (absent)

for (int x : s) cout << x;  // always sorted

Use cases

  • Membership tests (fast O(log n) with set, O(1) with unordered_set)
  • Keeping a sorted unique list
  • Finding intersections/unions

Your Task

Write intersection(vector<int> a, vector<int> b) that returns a sorted vector of elements present in both inputs, with no duplicates in the result.

Back
cppCtrl+Enter to run
Output

Click "Run" to execute your code.