How to Add an Element at the End of a Deque in C++? Last Updated : 27 Mar, 2024 Comments Improve Suggest changes Like Article Like Report 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 DequeThe following program illustrates how we can add an element at the end of a deque in C++: C++ // C++ Program to illustrates how we can add an element at // the end of a deque #include <deque> #include <iostream> using namespace std; int main() { // Initialize a deque with few elements deque<int> dq = { 10, 20, 30, 40 }; // Print the Original Deque cout << "Original Deque: "; for (int num : dq) { cout << num << " "; } cout << endl; // Declare the element to add at the end of the deque int element = 50; // Add the element at the end of the deque using // push_back dq.push_back(element); // Print the updated deque cout << "Updated Deque: "; for (int num : dq) { cout << num << " "; } return 0; } OutputOriginal Deque: 10 20 30 40 Updated Deque: 10 20 30 40 50 Time Complexity: O(1)Auxiliary Space: O(1) Comment More infoAdvertise with us Next Article How to Add an Element at the End of a Deque in C++? H heysaiyad Follow Improve Article Tags : C++ Programs C++ STL cpp-deque cpp-deque-functions CPP Examples +2 More Practice Tags : CPPSTL Similar Reads How to Add Element at Front of a Deque in C++? In C++, a deque is a vector like data structure that allows users to add and remove elements from both the front and the back ends. In this article, we will learn how to add an element at the beginning of a deque in C++. Example: Input: myDeque: {1, 2, 3} Output: myDeque = {11, 1, 2, 3}Add an Elemen 2 min read How to Add an Element at the End of List in C++? In C++, the Standard Template Library (STL) has a doubly-linked list container, known as std::list that offers various functions to manipulate elements. In this article, we will learn how to add an element at the end of a list in C++ STL. Example: Input: myList = {1, 2, 3}; Output: List after Elemen 2 min read How to Add Element at the End of a Vector in C++? Vector allows fast insertion and deletion at the end. In this article, we will learn different ways to add an element at the end of the vector.The easiest way to add an element at the end of vector is by using vector push_back() function. Letâs take a look at a simple example:C++#include <bits/st 4 min read How to Add an Element at the Front of a List in C++? In C++, the STL has a doubly linked list container defined as the std::list class template inside the <list> header. It stores the sequential data in non-contiguous memory locations. In this article, we will learn how to add an element at the beginning of a list in C++ STL. Example: Input: myL 2 min read How to Remove an Element from the End of a Deque in C++? In C++, deque is also called a double-ended queue where we can insert new elements at both the front and back of the container. In this article, we will learn to remove an element from the end of a deque in C++. Example: Input: myDeque = {1, 2, 3, 4, 5} Output: Deque after removal: 1 2 3 4 Removing 2 min read Like