1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
// forward_list::merge
#include <iostream>
#include <forward_list>
#include <functional>
int main ()
{
std::forward_list<double> first = {4.2, 2.9, 3.1};
std::forward_list<double> second = {1.4, 7.7, 3.1};
std::forward_list<double> third = {6.2, 3.7, 7.1};
first.sort();
second.sort();
first.merge(second);
std::cout << "first contains:";
for (double& x: first) std::cout << " " << x;
std::cout << std::endl;
first.sort (std::greater<double>());
third.sort (std::greater<double>());
first.merge (third, std::greater<double>());
std::cout << "first contains:";
for (double& x: first) std::cout << " " << x;
std::cout << std::endl;
return 0;
}
| |