intersection between vector c++

#include <iostream>
#include <vector>
#include <algorithm>

int main() {
    // Define two vectors
    std::vector<int> vector1 = {1, 2, 3, 4, 5};
    std::vector<int> vector2 = {3, 4, 5, 6, 7};

    // Sort both vectors
    std::sort(vector1.begin(), vector1.end());
    std::sort(vector2.begin(), vector2.end());

    // Create a vector to store the intersection
    std::vector<int> intersection;

    // Find the intersection of the two sorted vectors
    std::set_intersection(vector1.begin(), vector1.end(),
                          vector2.begin(), vector2.end(),
                          std::back_inserter(intersection));

    // Display the intersection
    std::cout << "Intersection: ";
    for (const auto& element : intersection) {
        std::cout << element << " ";
    }

    return 0;
}