How to Remove an Element from the End of a Deque in C++? Last Updated : 27 Mar, 2024 Comments Improve Suggest changes Like Article Like Report 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 an Element from the End of a Deque in C++To remove an element from the end of a std::deque in C++, we can use the std::deque::pop_back() method, which removes the last element of the deque, thereby reducing its size by one. Syntax of std::pop_backdequeName.pop_back();C++ Program to Remove an Element from the End of a DequeThe below example demonstrates how we can remove an element from the end of a deque in C++. C++ // C++ Program to demonstrates how we can remove an element // from the end of a deque #include <deque> #include <iostream> using namespace std; int main() { // Creating Deque with numbers deque<int> myDeque = { 1, 2, 3, 4, 5 }; // Printing Deque before removing end element cout << "Deque before removal: "; for (int num : myDeque) { cout << num << " "; } cout << endl; // Removing element from the end of the deque myDeque.pop_back(); // Printing Deque after removing the end of the deque cout << "Deque after removal: "; for (int num : myDeque) { cout << num << " "; } cout << endl; return 0; } OutputDeque before removal: 1 2 3 4 5 Deque after removal: 1 2 3 4 Time Complexity: O(1)Auxilliary Space: O(1) Comment More infoAdvertise with us Next Article How to Remove an Element from the End of a Deque in C++? G gauravggeeksforgeeks Follow Improve Article Tags : C++ Programs C++ STL cpp-deque CPP Examples +1 More Practice Tags : CPPSTL Similar Reads How to Remove an Element from the End of a List in C++? In C++, lists are data structures that allow us to store data of the same type in non-contiguous memory locations. In this article, we will learn how to remove an element from the end of a list in C++. Example Input: myList={10,20,30,40,50} Output: List Elements: 10 20 30 40Delete the Last Element f 2 min read How to Remove an Element from a Deque in C++? In C++ STL, a container called deque (known as a double-ended queue) allows us to insert and delete elements at both its beginning and its end. In this article, we will learn how to remove a specific element from a deque in C++ STL. Example: Input: myDeque= {4, 2, 3, 5, 2} Target = 4 Output: Deque A 2 min read How to Remove an Element from Front of Deque in C++? In C++, a deque (double-ended queue) is a data structure that allows efficient insertion and deletion at both ends. In this article, we will learn to remove an element from the beginning of a deque in C++. Example:Input: myDeque = {1, 2, 3, 4, 5}; Output: Deque After Removal: 2 3 4 5Removing the Fir 2 min read How to Remove an Element from a Set in C++? In C++, sets are a type of associative container in which each element has to be unique. The values are stored in a specific sorted order i.e. either ascending or descending. In this article, we will see how to remove specific elements from a set in C++. Example Input: set = {100,120,12,56,78,9,32,4 2 min read How to Add an Element at the End of a Deque in C++? 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, 2 min read Like