Sekvenční algoritmy “copy”

{“https:\/\/www.jdoodle.com\/a\/ciL?format=text”:”#include <iostream>\n#include <vector>\n#include <algorithm>\nusing namespace std;\n\ntemplate<typename C>\nvoid printValues(C container) {\n for(auto val : container)\n cout << val << ";";\n cout << endl;\n}\n\nint main() {\n \/\/ Generujeme \u010d\u00edsla 1..15\n vector<int> input;\n int value = 0;\n generate_n(back_inserter(input), 15, [value]() mutable { value++; return value; });\n \n \/\/ Kopirujeme prvn\u00edch 10 element\u016f\n vector<int> output(input.size());\n copy(input.begin(), next(input.begin(), 10), output.begin());\n \n \/\/ V\u00fdstup\n cout << "VSTUP:" << endl;\n printValues(input);\n cout << "V\u00ddSTUP:" << endl;\n printValues(output);\n return 0;\n}”,”https:\/\/www.jdoodle.com\/a\/ciM?format=text”:”#include <iostream>\n#include <vector>\n#include <algorithm>\nusing namespace std;\n\ntemplate<typename C>\nvoid printValues(C container) {\n for(auto val : container)\n cout << val << ";";\n cout << endl;\n}\n\nint main() {\n \/\/ Generujeme \u010d\u00edsla 1..20\n vector<int> input;\n int value = 0;\n generate_n(back_inserter(input), 20, [value]() mutable { value++; return value; });\n \n \/\/ Vkl\u00e1d\u00e1me prvn\u00edch 12 element\u016f\n vector<int> output;\n copy_n(input.begin(), 12, back_inserter(output));\n \n \/\/ V\u00fdstup\n cout << "VSTUP:" << endl;\n printValues(input);\n cout << "V\u00ddSTUP:" << endl;\n printValues(output);\n return 0;\n}”,”https:\/\/www.jdoodle.com\/a\/ciN?format=text”:”#include <iostream>\n#include <vector>\n#include <algorithm>\nusing namespace std;\n\ntemplate<typename C>\nvoid printValues(C container) {\n for(auto val : container)\n cout << val << ";";\n cout << endl;\n}\n\nint main() {\n \/\/ Generujeme \u010d\u00edsla 1..20\n vector<int> input;\n int value = 0;\n generate_n(back_inserter(input), 20, [value]() mutable { value++; return value; });\n \n \/\/ Vkl\u00e1d\u00e1me pouze sud\u00e1 \u010d\u00edsla\n vector<int> output;\n copy_if(input.begin(), input.end(), back_inserter(output), [](int item) { return item % 2 == 0; });\n \n \/\/ V\u00fdstup\n cout << "VSTUP:" << endl;\n printValues(input);\n cout << "V\u00ddSTUP:" << endl;\n printValues(output);\n return 0;\n}”,”https:\/\/www.jdoodle.com\/a\/ciP?format=text”:”#include <iostream>\n#include <vector>\n#include <algorithm>\nusing namespace std;\n\ntemplate<typename C>\nvoid printValues(C container) {\n for(auto val : container)\n cout << val << ";";\n cout << endl;\n}\n\nint main() {\n \/\/ Generujeme \u010d\u00edsla 1..20\n vector<int> input;\n int value = 0;\n generate_n(back_inserter(input), 20, [value]() mutable { value++; return value; });\n \n \/\/ M\u011bn\u00edme po\u0159\u00e1d\u00ed \u010d\u00edsel\n vector<int> output(input.size());\n copy_backward(input.begin(), input.end(), output.rend());\n \n \/\/ V\u00fdstup\n cout << "VSTUP:" << endl;\n printValues(input);\n cout << "V\u00ddSTUP:" << endl;\n printValues(output);\n return 0;\n}”}


Sekvenční algoritmy “copy”
Ohodnoťte tento článek