sort — not stable. stable_sort — preserves order of equal elements.
1struct Person {2 std::string name;3 int age;4};56std::vector<Person> p = {7 {"A", 30}, {"B", 25}, {"C", 30}8};910// sort — may reorder A and C11std::sort(p.begin(), p.end(),12 [](auto& a, auto& b) { return a.age < b.age; }13);1415// stable_sort — preserves A before C16std::stable_sort(p.begin(), p.end(),17 [](auto& a, auto& b) { return a.age < b.age; }18);