Wie man einen std::vector von std::pairs sortiert
Sortieren Sie 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;
});Sortieren Sie 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;
});Check out similar posts by category:
C/C++
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow