Last active
December 23, 2015 14:28
-
-
Save ichaos/6648565 to your computer and use it in GitHub Desktop.
c++ custom sort compare function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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