Facebook Page Twitter Page LinkedIn Page
× C++ Standard Library C++ STL Library


The C++ list::pop_front function is used to delete the first element of the list. Every deletion of element results into reducing the container size by one unless the list is empty.

Syntax

void pop_front();
void pop_front();

Parameters

No parameter is required.

Return Value

None.

Time Complexity

Constant i.e, Θ(1)

Example:

In the below example, the list::pop_front function is used to delete first elements of the list called MyList.

#include <iostream>
#include <list>
using namespace std;
 
int main (){
  list<int> MyList{100, 200, 300, 400, 500, 600};
  list<int>::iterator it;

  //deletes first element of the list
  MyList.pop_front();
  //deletes next first element of the list
  MyList.pop_front();

  cout<<"MyList contains:";
  for(it = MyList.begin(); it != MyList.end(); ++it)
    cout<<" "<<*it;

  return 0;
}

The output of the above code will be:

MyList contains: 300 400 500 600

❮ C++ - List