Algoritmy “fill” a “generate”

{“https:\/\/www.jdoodle.com\/a\/c21?format=text”:”#include <iostream>\n#include <vector>\n#include <algorithm>\nusing namespace std;\n\ntemplate<typename C>\nvoid printValues(C c) {\n for(auto val : c)\n cout << val << ";";\n cout << endl;\n}\n\nint main() {\n vector<int> data(10);\n fill(data.begin(), data.end(), 3);\n printValues(data);\n return 0;\n}”,”https:\/\/www.jdoodle.com\/a\/c22?format=text”:”#include <iostream>\n#include <vector>\n#include <algorithm>\nusing namespace std;\n\ntemplate<typename C>\nvoid printValues(C c) {\n for(auto val : c)\n cout << val << ";";\n cout << endl;\n}\n\nint main() {\n vector<int> data;\n fill_n(back_inserter(data), 10, 4);\n printValues(data);\n return 0;\n}”,”https:\/\/www.jdoodle.com\/a\/c23?format=text”:”#include <iostream>\n#include <vector>\n#include <algorithm>\nusing namespace std;\n\ntemplate<typename C>\nvoid printValues(C c) {\n for(auto val : c)\n cout << val << ";";\n cout << endl;\n}\n\nint main() {\n vector<int> data(10);\n int value = 0;\n generate(data.begin(), data.end(), [value]() mutable { value++; return value; });\n printValues(data);\n return 0;\n}”,”https:\/\/www.jdoodle.com\/a\/c24?format=text”:”#include <iostream>\n#include <vector>\n#include <algorithm>\nusing namespace std;\n\ntemplate<typename C>\nvoid printValues(C c) {\n for(auto val : c)\n cout << val << ";";\n cout << endl;\n}\n\nint main() {\n vector<int> data;\n int value = 0;\n generate_n(back_inserter(data), 15, [value]() mutable { value++; return value; });\n printValues(data);\n return 0;\n}”}


Algoritmy “fill” a “generate”
Ohodnoťte tento článek