You really should define a specific sorting order for your data.
For example, given:
1 2 3 4 5
|
string name;
string street;
string town;
string county;
string postCode;
|
It seems to me that you already have a basic sort order.
Group by zip.
Inside that group, group by county.
Inside that group, group by town.
Inside that group, group by street.
Inside that group, group by name.
There are variations, of course, and it depends entirely on how you wish to see the data. If, for example, you wish to sort primarily on a person’s name (because you are trying to find a person by name), and then by address, you would put your first sort criterion by name.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
bool compare_by_name_then_address( const addressCard& a, const addressCard& b )
{
if (a.name > b.name) return false;
if (a.name < b.name) return true;
if (a.postCode > b.postCode) return false;
if (a.postCode < b.postCode) return true;
if (a.county > b.county) return false;
if (a.county < b.county) return true;
...
return false;
}
|
For sorting the data primarily by zip, the function looks very much the same, just reorder the pairs in your comparison function.
Hope this helps.