Something a bit like this:
1 2 3 4 5 6 7 8 9 10
|
#include <algorithm>
bool sort_by_name(const Member& m1, const Member& m2) { return m1.name < m2.name; }
bool sort_by_postcode(const Member& m1, const Member& m2) { return m1.postcode < m2.postcode; }
// sort by name:
std::sort(member_vector.begin(), member_vector.end(), sort_by_name);
// sort by postcode
std::sort(member_vector.begin(), member_vector.end(), sort_by_postcode);
|
std::sort()
http://cplusplus.com/reference/algorithm/sort/
Last edited on
I tried it, but does not work yet..
Im trying to index the data.
Then sort it in a new vector.
and then show it on the screen.
1 2 3 4 5 6 7
|
void sort_on_postcode ()
{
vector <PostalCodeIndex> post_vector;
vector <PostalCodeIndex> post_vector_sorted;
for (int i=0; i<members.size(); i++)//for every member
}
|
Last edited on
"Doesn't work" is not a very good problem description.
Im trying to index the data. |
What's that supposed to mean?
Last edited on
Sorry, I will try to be more clear.
I declared an index-vector of index-structs.
Now I have to fill this index-vector by copying the name-value
and position-value from the base-array.
But I dont understand how I can fill it..