Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Alexeev N.E.
- #include <iostream>
- #include <vector>
- #include <ctime>
- #include <iomanip>
- #include <algorithm>
- #include <random>
- #define SIZE 10
- void reverse(std::vector<int> &vector)
- {
- std::cout << "REVERSE\n";
- std::reverse(vector.begin(), vector.end());
- }
- void sortHigh(std::vector<int>& vector)
- {
- std::cout << "Sort Ascending\n";
- std::sort(vector.begin(), vector.end());
- }
- void sortLess(std::vector<int>& vector)
- {
- std::cout << "Sort Descending\n";
- std::sort(vector.rbegin(), vector.rend());
- }
- using funcType = void (*)(std::vector<int>&);
- funcType check(std::vector<int>& vector)
- {
- int sum = 0;
- for(auto& now : vector)
- sum += now;
- if (sum == vector[0])
- return reverse;
- if (sum > vector[0])
- return sortHigh;
- if (sum < vector[0])
- return sortLess;
- std::cerr << "Fatal error!";
- exit(0);
- }
- int main()
- {
- std::mt19937 gen(static_cast<unsigned int>(time(nullptr)));
- std::uniform_int_distribution<int> dist(-100, 100);
- std::vector<int> vec(SIZE);
- for(auto& now : vec)
- now = dist(gen);
- std::cout << "Array:\n";
- for(auto& now : vec)
- std::cout << std::setw(4) << now << ' ';
- std::cout << std::endl;
- funcType funcPtr = check(vec);
- funcPtr(vec);
- std::cout << "Array after check:\n";
- for(auto& now : vec)
- std::cout << std::setw(4) << now << ' ';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement