I am trying to sort a vector of strings {"Josh 67", "Emily 42", "Rich 14", "Janet 1"} based on the age provided along with the names. I don't wanna use any loops and want to use STL Algorithms and lambda function to sort it.
auto SortString = [](string a, string b)
{
return a > b;
};
vector<string> SortedByAge(vector<string> unsorted)
{
sort(unsorted.begin(), unsorted.end(), SortString);
return unsorted;
}
int main()
{
vector<string> result = SortedByAge({"Josh 67", "Emily 42", "Rich 14", "Janet 1"});
for(auto x : result)
{
cout << x << endl;
}
}
This is the code I have so far, however, it does not seem to be working. I would appreciate any help.