How to Dequeue an Element from a Queue in C++? Last Updated : 29 Feb, 2024 Comments Improve Suggest changes Like Article Like Report 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 and enqueue the values {1, 2, 3, 4, 5}.Output: Queue after dequeue: {2, 3, 4, 5}, after dequeue the first element.Dequeuing an Element from a Queue in C++To dequeue an element from a queue in C++, we can use the std::queue::pop() function. This function deletes or dequeues the first element of the queue. C++ Program to Dequeue an Element from a Queue C++ // C++ Program to illustrate how to dequeue an element from // a queue #include <iostream> #include <queue> using namespace std; // Driver Code int main() { // Creating a queue of integers queue<int> q; // Enqueueing elements into the queue for (int i = 1; i <= 5; ++i) { q.push(i); } // Dequeueing an element from the queue q.pop(); // Displaying the queue elements while (!q.empty()) { cout << q.front() << " "; q.pop(); } cout << endl; return 0; } Output2 3 4 5 Time Complexity: O(1) Space Complexity: O(1) Comment More infoAdvertise with us Next Article How to Dequeue an Element from a Queue in C++? R rohitpant4532 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 Delete an Element from a Set in C++? A set in C++ is a container that stores unique elements in a sorted order. In this article, we will learn how to delete a specific element from a set. Example: Input: mySet = {5, 2, 8, 1, 4} Element to delete: 2 Output: mySet = {5, 1, 8, 4}Delete an Element from a Set in C++To delete a specific elem 2 min read How to Delete an Element from a Priority Queue in C++ ? In C++, a priority queue is a queue in which elements are arranged based on their priority values as each element has a priority value associated with it. In this article, we will learn how to delete an element from a priority queue in C++. For Example, Input: myPriorityQueue = {8, 6, 7, 5, 4, 2, 3} 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 Clear All Elements from a Deque in C++? In C++, deque also known as double-ended queue is a container provided by the Standard Template Library (STL) that allows efficient insertion and deletion at both ends. In this article, we will learn how to clear all elements from a deque in C++. Example: Input: myDeque = {10, 20, 30, 40}; Output: A 2 min read How to Replace an Element in a Deque in C++? In C++, deque (short for double-ended queue) allows fast insertions and deletions at both its beginning and its end. In this article, we will learn how to replace a specific element in a deque in C++. Example: Input: myDeque: {1, 2, 3, 4, 5, 3, 7} Output: // Replaced element 3 with 10 Updated Deque: 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 Delete an Element from an Array in C++? In C++, arrays are data structures that allow users to store data of the same type in contiguous memory locations. In this article, we will learn how to delete an element from an array in C++. Example: Input:myarr = {20, 5, 1, 10, 15};Target: 1Output:Array after deletion: 20 5 10 15Remove an Element 3 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 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 Like