Wie man einen std::vector von std::pairs sortiert

Sortiere einen std::vector<std::pair<...>> in-place nach dem first-Element des Paares:

sort_by_first.cpp
std::sort(ret.begin(), ret.end(), [](const auto& a, const auto& b) {
    return a.first < b.first;
});

Sortiere einen std::vector<std::pair<...>> in-place nach dem second-Element des Paares:

sort_by_second.cpp
std::sort(ret.begin(), ret.end(), [](const auto& a, const auto& b) {
    return a.second < b.second;
});

Ähnliche Beiträge nach Kategorie: C/C++