Skip to content
Related Articles

Related Articles

list pop_front() function in C++ STL

View Discussion
Improve Article
Save Article
  • Difficulty Level : Easy
  • Last Updated : 13 Jun, 2022
View Discussion
Improve Article
Save Article

The list::pop_front() is a built-in function in C++ STL which is used to remove an element from the front of a list container. This function thus decreases the size of the container by 1 as it deletes the element from the front of a list. Syntax:

list_name.pop_front();

Parameters: The function does not accept any parameter. Return Value: This function does not returns anything. Below program illustrate the list::pop_front() function in C++ STL: 

CPP




// CPP program to illustrate the
// list::pop_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()
 demoList.push_back(10);
 demoList.push_back(20);
 demoList.push_back(30);
 demoList.push_back(40);
 
 // Initial List:
 cout << "Initial List: ";
 for (auto itr = demoList.begin(); itr != demoList.end(); itr++)
  cout << *itr << " ";
 
 // removing an element from the front of List
 // using pop_front
 demoList.pop_front();
 
 // List after removing element from front
 cout << "\n\nList after removing an element from front: ";
 for (auto itr = demoList.begin(); itr != demoList.end(); itr++)
  cout << *itr << " ";
 
 return 0;
}

Output:

Initial List: 10 20 30 40 

List after removing an element from front: 20 30 40

Time Complexity: O(n)

Auxiliary Space: O(1)

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!