VOOZH about

URL: https://www.geeksforgeeks.org/cpp/how-to-add-an-element-at-the-end-of-a-deque-in-cpp/

⇱ How to Add an Element at the End of a Deque in C++? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Add an Element at the End of a Deque in C++?

Last Updated : 23 Jul, 2025

In C++, a deque is a flexible data structure that supports the insertion and deletion of elements from both ends efficiently. In this article, we will learn how to add an element at the end of a deque in C++.

Example:

Input:
myDeque ={10,20,30,40}

Output:// added element 50 at the end
myDeque ={10,20,30,40,50}

Add an Element at the Back of a Deque in C++

To add an element at the end of a std::deque in C++, we can use the deque::push_back() method. This method takes the element to be inserted as an argument and inserts it to the end of the deque.

Syntax:

deque_name.push_back(value);

C++ Program to Add an Element at the End of a Deque

The following program illustrates how we can add an element at the end of a deque in C++:


Output
Original Deque: 10 20 30 40 
Updated Deque: 10 20 30 40 50 

Time Complexity: O(1)
Auxiliary Space: O(1)



Comment