0
Need of stable sort
Hi If i am not wrong, stable sort maintains relative order. Refer code below: id for ketan and Ketan is same... so when sorted, the one which was inserted first (Ketan) is maintained after sorting. id for abc and Abc is same... so when sorted, the one which was inserted first (abc) is maintained after sorting. So, if sort is giving this output, what is need of stable_sort ? https://code.sololearn.com/cbAsACc779sz/?ref=app
2 Answers
+ 2
The difference is shown when more items are added.
https://code.sololearn.com/culr3G12ibgB/?ref=app
+ 4
Quoted from https://en.cppreference.com/w/cpp/algorithm/stable_sort
"The order of equivalent elements is guaranteed to be preserved"
This is different with std::sort Description, as quoted from https://en.cppreference.com/w/cpp/algorithm/sort
"The order of equivalent elements is not guaranteed to be preserved"