kenshiro182 | Un exemple
Code :
- #include <algorithm>
- #include <iostream>
- #include <vector>
- #include <iterator>
- int main(int argc, char *argv[])
- {
- int array1[] = {1, 2, 3, 4};
- int array2[] = {3, 4, 0, 4, 1};
- size_t LEN1 = sizeof(array1)/sizeof(array1[0]);
- size_t LEN2 = sizeof(array2)/sizeof(array2[0]);
- std::sort(array1, array1+LEN1);
- std::sort(array2, array2+LEN2);
-
- typedef std::vector<int> TotoT;
- TotoT toto;
- std::set_intersection(array1, array1+LEN1, array2, array2+LEN2,
- std::back_inserter<TotoT>(toto));
-
- std::copy(toto.begin(), toto.end(), std::ostream_iterator<int>(std::cout, " " ));
- std::cout << std::endl;
-
- return 0;
- }
|
|