Skip to content

Instantly share code, notes, and snippets.

@toddlipcon
Created February 22, 2019 20:40
Show Gist options
  • Save toddlipcon/d45d943dc281d008eb14bf7ef7d82c0e to your computer and use it in GitHub Desktop.
Save toddlipcon/d45d943dc281d008eb14bf7ef7d82c0e to your computer and use it in GitHub Desktop.
#include <algorithm>
#include <iostream>
#include <vector>
#include <utility>
using namespace std;
int main( int argc, char *argv[] ) {
vector<pair<int, int>> pairs = {
{2, 3},
{2, 4},
{2, 3},
{1, 2}};
std::sort(pairs.begin(), pairs.end(), [](const pair<int, int>& a, const pair<int, int>& b) {
return a.second - b.second;
});
for (auto& p : pairs) {
cout << p.first << ", " << p.second << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment