Skip to content

Instantly share code, notes, and snippets.

@ichaos
Last active December 23, 2015 14:28
Show Gist options
  • Save ichaos/6648565 to your computer and use it in GitHub Desktop.
Save ichaos/6648565 to your computer and use it in GitHub Desktop.
c++ custom sort compare function
#include <algorithm>
using namespace std;
struct people {
int s;
int b;
int i;
bool operator<(const people &o) const {
if (s == o.s) return b > o.b;
else return s < o.s;
}
};
struct customLess {
bool operator()(const people &a, const people &b) {
if (a.s == b.s) return a.b > b.b;
else return a.s < b.s;
}
};
int main () {
return 0;
vector<people> ps;
sort(ps.begin(), ps.end());
sort(ps.begin(), ps.end(), customLess());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment