|
Academic Work Personal
|
CPP /
Sort a vector of custom objects / sort a vector of pointers
Sort objects:
struct taxpayersCmp{
bool operator()(const taxpayer &a,const taxpayer &b) const{
return a.Float<b.Float;
}
} taxpayersCmp_;
//...
std::sort(taxpayers.begin(),taxpayers.end(),taxpayersCmp_);
This tip is from http://www.cplusplus.com/forum/general/5885/ . Sort objects whose pointers are stored in a vector:
static struct nodeCmp {
bool operator()(const shared_ptr<Node>& a, const shared_ptr<Node>& b) const {
return a->getValue() < b->getValue();
}
} nodeCmp_;
//...
std::sort( vec.begin(), vec.end(), nodeCmp_ );
|
![]() anime | bash | blogs | bsd | c/c++ | c64 | calc | comics | convert | cube | del.icio.us | digg | east | eBooks | egeszseg | elite | firefox | flash | fun | games | gimp | google | groovy | hardware | hit&run | howto | java | javascript | knife | lang | latex | liferay | linux | lovecraft | magyar | maths | movies | music | p2p | perl | pdf | photoshop | php | pmwiki | prog | python | radio | recept | rts | scala | scene | sci-fi | scripting | security | shell | space | súlyos | telephone | torrente | translate | ubuntu | vim | wallpapers | webutils | wikis | windows Blogs and Dev. * Ubuntu Incident Places Debrecen | France | Hungary | Montreal | Nancy Notes Hobby Projects * Jabba's Codes Quick Links [ edit ] |