How to Remove an Element from Front of Deque in C++? Last Updated : 27 Mar, 2024 Comments Improve Suggest changes Like Article Like Report 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 First Element from a Deque in C++To remove an element from the beginning of a deque in C++, we can use the std::deque::pop_front() member function of std::deque that dequeues the first element, effectively removing it from the deque. Syntax to Use std::deque::pop_frontdequeName.pop_front();C++ Program to Remove an Element from the Beginning of a DequeThe below program demonstrates how we can remove the first element from the beginning of a deque in C++. C++ // C++ Program to demonstrates how we can remove the first // element from the beginning of a deque #include <deque> #include <iostream> using namespace std; int main() { // Creating a deque deque<int> myDeque = { 1, 2, 3, 4, 5 }; // Printing the original deque cout << "Original Deque: "; for (int num : myDeque) { cout << num << " "; } cout << endl; // Removing the element from the beginning of the deque myDeque.pop_front(); // Printing the updated deque cout << "Deque After Removal: "; for (int num : myDeque) { cout << num << " "; } cout << endl; return 0; } OutputOriginal Deque: 1 2 3 4 5 Deque After Removal: 2 3 4 5 Time Complexity: O(1)Auxiliary Space: O(1) Comment More infoAdvertise with us Next Article How to Remove an Element from Front of Deque in C++? G gauravgandal 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 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 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 How to Remove All Occurrences of an Element from Deque in C++? In C++, a deque (double-ended queue) is a container that allows insertion and deletion at both its beginning and end. In this article, we will learn how to remove all occurrences of a specific element from a deque in C++. Example: Input: deque = {1, 2, 3, 4, 3, 2, 1} element to remove = 2 Output: Up 2 min read 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 Dequeue an Element from a Queue in C++? In C++, queues are a type of container adaptors that operate in a first in first out (FIFO) type of arrangement. Elements are inserted at the back (end) and are deleted from the front. In this article, we will learn how to dequeue an element from a queue in C++ STL. Example: Input: Create a queue an 2 min read Like