isShorter(const string &s1, const string &s2)
{
    return s1.size() < s2.size();
}
stable_sort(ret.begin(), ret.end(), isShorter);

either using stable_sort or sort the result is shown in the attachment.
meanwhile:
"By calling stable_sort, we can maintain
alphabetical order among those elements that have the same length:" - C++ Primer 5th edi.

which would mean stable_sort would arrange those string with the same length in alphabetical order, is it?

which would mean stable_sort would arrange those string with the same length in alphabetical order, is it?

No, stable_sort would retain the original order of those strings with the same length.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.