Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Example program
- #include <iostream>
- #include <string>
- #include <vector>
- #include <algorithm>
- int main()
- {
- std::vector<int> v = {7, 4, 9,2, 1, 5, 6, 3, 8};
- std::vector<double> values = {4, 5, 3};
- auto maxIt = std::max_element(values.begin(), values.end(), [](const auto& a, const auto& b) { return std::max(-a, a) < std::max(-b, b); });
- auto maxIndex = std::distance(values.begin(), maxIt); // index of X=0, Y=1 or Z=2 coordiante
- bool asc = values[maxIndex] >= 0; // sort ascending if the delta value is positive, else descending
- std::cout << maxIndex << std::endl;
- std::cout << asc << std::endl;
- auto sortFunc = [](const auto left, const auto right, bool asc) { return asc ? left < right : left > right; };
- std::sort(v.begin() + 1, v.end() - 1, [&sortFunc, &asc](const auto&a, const auto&b){ return sortFunc(a, b, asc); });
- for(const auto& i : v)
- {
- std::cout << i << std::endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement