![]() |
VOOZH | about |
The forward_list::insert_after() is a builtin function in C++ STL which gives us a choice to insert elements at the position just after the element pointed by a given iterator in the forward list. The arguments in this function are copied at the desired position. Syntax:
forward_list_name.insert_after(iterator position, element) or, forward_list_name.insert_after(iterator position, n, element) or, forward_list_name.insert_after(iterator position, itr1, itr2) or, forward_list_name.insert_after(iterator position, list)
Parameters: The function accepts different parameters based on the above different syntaxes. Let's see every parameter in details and working of the above syntax.
Return Value :This function returns an iterator that points to the last inserted element. Below program illustrates the above mentioned function:
After Syntax 1: 1 20 2 3 4 5 After Syntax 2: 1 20 2 20 20 20 3 4 5 After Syntax 3: 1 20 2 20 20 20 8 9 10 3 4 5 After Syntax 4: 1 20 2 20 20 20 8 9 10 50 60 3 4 5
Time Complexity: O(n)
Auxiliary Space: O(1)