How to select elements with certain value from STL container and move them at the end of that container?
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.
Considering you made a comment about wanting to use std::vector, I’d suggest using std::partition or std::stable_partition, i.e.:
This code will move all elements of the vector that are equal to 5 to the end of the vector, keeping the relative order of the remaining elements in tact.