When you have overloaded operator<
you can just use std::stable_sort(begin(fruit), end(fruit));
Instead of overload the operator before (so if you only want to use this kind of comparison once, you can use a lambda expression like this:
std::stable_sort(begin(fruit), end(fruit), [](auto const& a, auto const& b){
return strcmp (a.fruit_name, b.fruit_name) < 0;
});
The syntax in the reference (all these iterators) might be confusing you. For now, just use begin
and end
and when you get more familiar with the language, you should try to understand iterators.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…