Lets say I have a linked list which contains the following:
1, 2, 4, 5, 6, 2, 3, 2
now lets say I wish to convert this to:
1, 10, 2, 4, 5, 6, 10, 2, 3, 10, 2
i.e. insert 10 before all 2’s.
How should I do this?
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.
Off the top of my head
Simple enough. You don’t need to worry about iterator invalidation because
inserton astd::listdoes not invalidate any iterators. It’s one of the advantages of usingstd::list.