C++ Standard Library C++ STL Library

C++ <deque> - pop_front() Function



The C++ deque::pop_front function is used to delete the first element of the deque. Every deletion of element results into reducing the container size by one unless the deque 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 example below, the deque::pop_front function is used to delete the first element of the deque called MyDeque.

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

  //deletes first element of the deque
  MyDeque.pop_front();
  //deletes next first element of the deque
  MyDeque.pop_front();

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

  return 0;
}

The output of the above code will be:

The deque contains: 300 400 500 600

❮ C++ <deque> Library