# ex_intersect_sorted¶

ows how to find an intersection of two sorted vectors of dat

## Categories:¶

• core/algorithms/basic_algorithms.hh

## Program source:¶

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 #include #include #include #include /** @brief Shows how to find an intersection of two sorted vectors of data * * CATEGORIES: core/algorithms/basic_algorithms.hh * KEYWORDS: algorithms; data structures */ int main(const int argc, const char* argv[]) { std::vector range1({1,2,3,5,6,7}), range2({5,6,7,8,9,10}), repeated; // Note that both range1 and range2 are already sorted! core::algorithms::intersect_sorted(range1.begin(), range1.end(), range2.begin(), range2.end(), repeated); // Print the element found as the intersection between the two ranges std::copy(repeated.begin(), repeated.end(), std::ostream_iterator(std::cout, " ")); std::cout << "\n"; }