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


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

Syntax

void pop_back();
void pop_back();

Parameters

No parameter is required.

Return Value

None.

Time Complexity

Constant i.e, Θ(1).

Example:

In the below example, the deque::pop_back function is used to delete the last elements 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 last element of the deque
  MyDeque.pop_back();
  //deletes next last element of the deque
  MyDeque.pop_back();

  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: 100 200 300 400

❮ C++ - Deque