forward_list::before_begin() is an inbuilt function in C++ STL that returns an iterator that points to the position before the first element of the forward_list. Forward list in STL is a singly linked list implementation. This function comes under the <forward_list> header file.
Syntax:
forwardlist_name.before_begin()
Return value: The function returns an iterator that points to the position before the first element of the forward_list.
The below program demonstrates the above function:
CPP
#include <bits/stdc++.h>
using namespace std;
int main()
{
forward_list< int > fl = { 20, 30, 40, 50 };
auto it = fl.before_begin();
fl.insert_after(it, 10);
cout << "Element of the list are:" << endl;
for ( auto it = fl.begin(); it != fl.end(); ++it)
cout << *it << " " ;
return 0;
}
|
OutputElement of the list are:
10 20 30 40 50
Time Complexity: O(1)
Auxiliary Space: O(1)
Must Read:
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.