C++ List push_front
The push_front method in C++ List inserts a new element at the front of the list, thereby expanding the size of the list by one element.
The push_front(0) method inserts a new element with a value of 0 at the start of the collection.
Syntax
Suppose an element is 'x':
void push_front(const value_type& x);
Parameter
The variable x represents the value that will be added to the start of the list.
Return value
It does not return any value.
Example
Let's see a simple example
#include <iostream>
#include<list>
using namespace std;
int main()
{
list<int> li={20,30,40,50};
li.push_front(10);
list<int>::iterator itr;
for(itr=li.begin();itr!=li.end();++itr)
cout<<*itr<<",";
return 0;
}
Output:
10,20,30,40,50
In this instance, the push_front method adds the value '10' at the start of the linked list.