Algoritmy “equal” a “mismatch”

{“https:\/\/www.jdoodle.com\/a\/ciX?format=text”:”#include <iostream>\n#include <vector>\n#include <algorithm>\nusing namespace std;\n\nint main() {\n vector<int> input;\n fill_n(back_inserter(input), 10, 4);\n \n vector<int> output1, output2;\n copy(input.begin(), input.end(), back_inserter(output1));\n copy(input.begin(), input.end(), back_inserter(output2));\n output2[4] = 8;\n \n cout << boolalpha;\n cout << "Shoda output1: " << equal(input.begin(), input.end(), output1.begin()) << endl;\n cout << "Shoda output2: " << equal(input.begin(), input.end(), output2.begin()) << endl;\n \n return 0; \n}\n\n\n”,”https:\/\/www.jdoodle.com\/a\/ciY?format=text”:”#include <iostream>\n#include <vector>\n#include <algorithm>\nusing namespace std;\n\nint main() {\n \/\/ Generuje \u010d\u00edsla 0..9\n vector<int> data1;\n int value = 0;\n generate_n(back_inserter(data1), 10, [&value](){ return value++; });\n \n \/\/ Okopirujeme vektor\n vector<int> data2;\n copy(data1.begin(), data1.end(), back_inserter(data2));\n data2[7] = 100;\n \n \/\/ Mismatch\n auto p = mismatch(data1.begin(), data1.end(), data2.begin());\n \n cout << "Hodnota rozdilu v data1: " << *(p.first) << endl;\n cout << "Hodnota rozdilu v data2: " << *(p.second) << endl;\n cout << "Index rozdilu: " << distance(data1.begin(), p.first) << endl;\n return 0;\n}”}


Algoritmy “equal” a “mismatch”
Ohodnoťte tento článek