I want to know what are difference(s) between vector‘s push_back and insert functions.
Is there a structural difference(s)?
Is there a really big performance difference(s)?
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.
The biggest difference is their functionality.
push_backalways puts a new element at the end of thevectorandinsertallows you to select new element’s position. This impacts the performance.vectorelements are moved in the memory only when it’s necessary to increase it’s length because too little memory was allocated for it. On the other handinsertforces to move all elements after the selected position of a new element. You simply have to make a place for it. This is whyinsertmight often be less efficient thanpush_back.