Hi guys,
I've got a string of 3 characters, first 2 are numbers and last one is a letter
I was thinking of pushbacking it to vector <pair <int, char > > v and then sorting it with
bool f1(pair <int,char> a, pair <int,char> b)
{
return a.first < b.first || a.second < b.second;
}
sort(v.begin(),v.end(),f1);
2 questions, can I use that function to sort first through numbers then through letters, and second how do i change first 2 char numbers to an int number?
Do you want to sort first by the letter and then by the number? You could store "10A" as "A10" and lexicographical sort would do the work for you.
The logic of your f1() ... there are three cases:
1. a<b
2. a==b
3. b<a
The first and last are clearcut: the character alone will rule the order.
Only on case of equality does the lesser member of the pair make a difference.