list push_front() function in C++ STL

The list::push_front() is a built-in function in C++ STL which is used to insert an element at the front of a list container just before the current top element. This function also increases the size of the container by 1.


list_name.push_front(dataType value)

Parameters: This function accepts a single parameter value. This parameter represents the element which is needed to be inserted at the front of the list container.

Return Value: This function does not return anything.

Below program illustrate the list::push_front() function in C++ STL:





// CPP program to illustrate the
// list::push_front() function
#include <bits/stdc++.h>
using namespace std;
int main()
    // Creating a list
    list<int> demoList;
    // Adding elements to the list
    // using push_back()
    // Initial List:
    cout << "Initial List: ";
    for (auto itr = demoList.begin(); itr != demoList.end(); itr++)
        cout << *itr << " ";
    // Adding elements to the front of List
    // using push_front
    // List after adding elements to front
    cout << "\n\nList after adding elements to the front:\n";
    for (auto itr = demoList.begin(); itr != demoList.end(); itr++)
        cout << *itr << " ";
    return 0;



Initial List: 10 20 30 40 

List after adding elements to the front:
5 10 20 30 40

Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to 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.

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at to report any issue with the above content.