What is the behavior of std::sort when used with ints that are equal is it going to keep them in the same order or just do some unpredictable stuff?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
std::sortdoesn’t preserve the order of the equivalent elements,std::stable_sortdoes. However, in case ofint‘s you will not notice the difference unless you use some non-trivial ordering as in the following example:Here is another example when
std::stable_sortis a more suitable candidate thanstd::sort