C++ List insert()C++ List insert() function inserts a new element just before the specified position. It increases the size of the list container by the number of elements added in the list. SyntaxParameterpos: It defines the position before which the new element is to be inserted. value: The value to be inserted. n: Number of times the value to be occurred. ( first,last): It defines the range of the elements to be inserted at position pos. Return valueIt returns an iterator pointing to the newly constructed element. Example 1Let's see a simple example Output: 51234 In this example, iterator points to the first element of the list. Therefore, 5 is inserted before the first element of the list using insert() function. Example 2Let's see a simple example when n is given. Output: java java C is a language In this example, insert() function inserts the string "java" 2 times before the first element of the list. Example 3Let's see a simple example Output: 6 7 8 9 1 2 3 4 5 In this example, range(first, last) of list li1 is given. Therefore, the insert() function inserts the elements between this range in the list li. Next Topicpush_back() Function |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India