C++ List push_front()

Last Updated : 18 May 2026

List push_front() Function

In C++, the list::push_front() function is used to insert a new element at the beginning of the list container. Whenever a new element is inserted using this function, the size of the list increases by one.

C++ List push_front()

It is commonly used when elements need to be added at the front of the list efficiently. Since lists are implemented as doubly linked lists, insertion at the beginning is fast and does not invalidate iterators or references.

Syntax

It has the following syntax.

Parameters

x: It is the value to be inserted in the beginning of the list.

Return value

It does not return any value.

Examples of the List push_front() Function

Here, we are going to discuss several examples to demonstrate the List push_front() Function Function.

Example 1: Insert an Element at the Beginning of a List

This example demonstrates how to insert an integer element at the beginning of a list using the push_front() function.

Output:

10,20,30,40,50

Explanation:

In this example, push_front() function inserts the element '10' in the beginning of the list.