Algoritmy “unique” a “reverse”

{“https:\/\/www.jdoodle.com\/a\/ctl?format=text”:”#include <iostream>\n#include <vector>\n#include <algorithm>\nusing namespace std;\n\ntemplate<typename C>\nvoid print(C container) {\n for(auto value: container)\n cout << value << ";";\n cout << endl;\n}\n\nint main() {\n vector<int> data = {0, 1, 1, 1, 1, 0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3};\n print(data);\n auto it = unique(data.begin(), data. end());\n data.resize(distance(data.begin(), it));\n print(data);\n \n}”,”https:\/\/www.jdoodle.com\/a\/ctm?format=text”:”#include <iostream>\n#include <vector>\n#include <algorithm>\nusing namespace std;\n\ntemplate<typename C>\nvoid print(C container) {\n for(auto value: container)\n cout << value << ";";\n cout << endl;\n}\n\nint main() {\n vector<int> data = {0, 1, 1, 1, 1, 0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3};\n vector<int> data2;\n unique_copy(data.begin(), data. end(), back_inserter(data2));\n print(data);\n print(data2);\n \n}”,”https:\/\/www.jdoodle.com\/a\/ctp?format=text”:”#include <iostream>\n#include <vector>\n#include <algorithm>\nusing namespace std;\n\ntemplate<typename C>\nvoid print(C container) {\n for(auto value : container)\n cout << value << ";";\n cout << endl;\n}\n\nint main() {\n auto generator = []() {\n static int value = 0;\n return ++value;\n };\n vector<int> data;\n generate_n(back_inserter(data), 20, generator);\n \n print(data);\n reverse(data.begin(), data.end());\n print(data);\n reverse(data.begin(), data.end());\n print(data);\n return 0; \n}”,”https:\/\/www.jdoodle.com\/a\/ctr?format=text”:”#include <iostream>\n#include <vector>\n#include <algorithm>\nusing namespace std;\n\ntemplate<typename C>\nvoid print(C container) {\n for(auto value : container)\n cout << value << ";";\n cout << endl;\n}\n\nint main() {\n auto generator = []() {\n static int value = 0;\n return ++value;\n };\n vector<int> data;\n generate_n(back_inserter(data), 20, generator);\n \n vector<int> data2;\n reverse_copy(data.begin(), data.end(), back_inserter(data2));\n \n print(data);\n print(data2);\n return 0; \n}”}


Algoritmy “unique” a “reverse”
Ohodnoťte tento článek