Hello, this is the question in which I am facing problem. I just want to know how the comparator will work and how the strings are passed as s1 and s2 from vector ?
Given the following code snippet :
bool comp(string s1, string s2)
{
if(s1.length() < s2.length())
return 1;
else if(s1.length() > s2.length())
return 0;
else return s1 < s2;
}
vector< string > data = {“b”, “a”, “c”, “abc”, “bca”, “xy”};
sort(data.begin(), data.end(), comp);
for(string item : data)
cout << item << " ";
Choose the correct output :
