Search
 
SCRIPT & CODE EXAMPLE
 

CPP

c++ set intersection

std::set_intersection(first, first + 5, second, second + 5, v1.begin());
Comment

c++ set intersection

// CPP program to illustrate
// std :: set_intersection
 
#include <bits/stdc++.h>
 
int main()
{
    int first[] = { 5, 10, 15, 20, 25 };
    int second[] = { 50, 40, 30, 20, 10 };
    int n = sizeof(first) / sizeof(first[0]);
 
    std::vector<int> v1(5);
    std::vector<int> v2(5);
    std::vector<int>::iterator it, ls;
 
    std::sort(first, first + 5);
    std::sort(second, second + 5);
 
    // Print elements
    std::cout << "First array :";
    for (int i = 0; i < n; i++)
        std::cout << " " << first[i];
    std::cout << "
";
 
    // Print elements
    std::cout << "Second array :";
    for (int i = 0; i < n; i++)
        std::cout << " " << second[i];
    std::cout << "

";
 
    // std :: set_intersection
    ls = std::set_intersection(first, first + 5, second, second + 5, v1.begin());
 
    std::cout << "The intersection has " << (ls - v1.begin()) << " elements:";
    for (it = v1.begin(); it != ls; ++it)
        std::cout << ' ' << *it;
    std::cout << "
";
 
    return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: square gcode 
Cpp :: even and odd in c++ 
Cpp :: c++ formatting 
Cpp :: c++ garbage collection 
Cpp :: remove something from stringstream 
Cpp :: input c++ 
Cpp :: c++ program to convert fahrenheit to celsius 
Cpp :: c/c++ windows api socket wrappers 
Cpp :: c++ std map initializer list 
Cpp :: cpp malloc 
Cpp :: maximum subarray leetcode c++ 
Cpp :: how to find factorial of number in c++ 
Cpp :: c++ map 
Cpp :: how to use power in c++ 
Cpp :: order 2d array in c++ 
Cpp :: remove linked list elements leetcode 
Cpp :: memcpy in cpp 
Cpp :: unique element in array in c 
Cpp :: c++ last element of vector 
Cpp :: C++ Syntax for Passing Arrays as Function Parameters 
Cpp :: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/ 
Cpp :: c++ include difference between quotes and brackets 
Cpp :: crud with template c++ 
Cpp :: how to read rotary encoder c++ 
Cpp :: find no of occurences of each letter in string c++ 
Cpp :: adding two dates using necessary member function in c++ 
Cpp :: print float up to 3 decimal places in c++ 
Cpp :: cout alternative c++ 
Cpp :: tu hi hai aashiqui song lyrics 
Cpp :: convert into acsii c++ 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =