The list::insert() is used to insert the elements at any position of list. This function takes 3 elements, position, number of elements to insert and value to insert. If not mentioned, number of elements is default set to 1.
insert(pos_iter, ele_num, ele)
Parameters: This function takes in three parameters:
- pos_iter: Position in the container where the new elements are inserted.
- ele_num: Number of elements to insert. Each element is initialized to a copy of val.
- ele: Value to be copied (or moved) to the inserted elements.
Return Value: This function returns an iterator that points to the first of the newly inserted elements.
The list after inserting 1 element using insert() is : 2 2 5 2 The list after inserting multiple elements using insert() is : 2 2 5 7 7 2
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- How to insert elements in C++ STL List ?
- map insert() in C++ STL
- set insert() function in C++ STL
- emplace vs insert in C++ STL
- multimap insert() in C++ STL
- unordered_map insert in C++ STL
- std::string::insert() in C++
- unordered_multimap insert() in C++ STL
- unordered_multiset insert() function in C++ STL
- deque insert() function in C++ STL
- vector insert() function in C++ STL
- Insert string at specified position in PHP
- 2-3 Trees | (Search and Insert)
- unordered_set insert() function in C++ STL
- multiset insert() function in C++ STL
- How to insert an item at the beginning of an array in PHP ?
- How to insert line break before an element using CSS?
- How to insert HTML into view from AngularJS controller?
- How to insert spaces/tabs in text using HTML/CSS?
- Inserting elements in std::map (insert, emplace and operator )
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.