meow00
asked on
How do I sort a vector of struct using different methods ?
Hi experts,
typedef struct{
int head ;
int tail ;
// ... blah
} Animal ;
I want to sort vector<Animal>. In some cases I want to sort by head; but in other cases, I want to sort by tail ....
so how do I do this ? should I write a predicator ? if so, how to do it ?
many thanks !
typedef struct{
int head ;
int tail ;
// ... blah
} Animal ;
I want to sort vector<Animal>. In some cases I want to sort by head; but in other cases, I want to sort by tail ....
so how do I do this ? should I write a predicator ? if so, how to do it ?
many thanks !
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://www.msoe.edu/eecs/ce/courseinfo/stl/sort.htm
Some code samples
http://www.codeproject.com/vcpp/stl/sorted_vector.asp