How to Declare a Deque in C++? Last Updated : 27 Mar, 2024 Comments Improve Suggest changes Like Article Like Report In C++, deques are sequence containers in which a user can insert data at both the front and the end of the container. In this article, we will learn how to declare a deque in C++. Declaring a Deque in C++Deque is defined as the class template std::deque in the <deque> header file. So to create a deque in C++, we first have to include the <deque> header file. Then we can declare the deque by creating an instance of the template by passing the type of element as the template parameter and assign some identifier to this intance. Syntax to Declare a Dequedeque<dataType> dequeName;Here, dataType: is the type of data deque will store.dequeName: is the name of the deque container.C++ Program to Declare a DequeThe following program illustrates how we can declare a deque in C++: C++ // C++ Program to illustrates how we can declare a deque #include <deque> #include <iostream> using namespace std; int main() { // Declaring a deque deque<int> dq; // Adding elements to the deque dq.push_back(1); dq.push_back(2); dq.push_back(3); dq.push_back(4); dq.push_back(5); // Printing deque elements cout << "Deque Elements:"; for (int num : dq) { cout << num << " "; } cout << endl; return 0; } OutputDeque Elements:1 2 3 4 5 Time Complexity: O(N), where N is the number of deque elements.Auxiliary Space: O(N) Comment More infoAdvertise with us Next Article How to Sort a Deque in C++? A anjalibo6rb0 Follow Improve Article Tags : C++ Programs C++ STL cpp-deque CPP Examples +1 More Practice Tags : CPPSTL Similar Reads How to Compare Two Deques in C++? In C++ the Standard Template Library (STL) provides a container called deque (short for double-ended queue) that allows fast insertions and deletions at both ends of the deque. In this article, we will learn how to compare two deques in C++. Example: Input: deque1 = {10,20,30}; deque2 = {10,20,30}; 2 min read How to Sort a Deque in C++? In C++, the STL provides a container called a double-ended queue which is popularly known as deque. This container allows fast insertions and deletions at both ends of the container. In this article, we will learn how to sort a deque in C++. Example: Input: myDeque = {30, 10, 20,50,40} Output: 10 20 2 min read How to Create a Deque of Sets in C++? In C++, a container called deque is a queue like container but allows for fast insertions and deletions at both ends. In this article, we will learn how to create a deque of sets in C++. Example: Input: mySet1 = {1, 4, 8, 9, 11} mySet2 = {1, 2, 3, 5, 7} Output: myDeque: [ {1, 4, 8, 9, 11}, {1, 2, 3, 2 min read How to Create a Deque of Maps in C++? In C++, the Standard Template Library (STL) provides a container called deque that allows efficient insertion and deletion operations at both ends of the container. A map is an associative container that stores elements in key-value pairs.In this article, we will learn how to create a deque of maps 2 min read How to Create a Stack of Deque in C++? In C++, the stack is a container in which new elements are added from one end (top) and removed from that end only whereas a deque (double-ended queue) are sequence container with the feature of expansion and contraction on both ends. In this article, we will learn how to create a stack of deque in 2 min read How to Create a Deque of Arrays in C++? In C++, a deque (double-ended queue) is a data structure that allows insertion and deletion at both ends whereas arrays are fixed-size collections of elements. In this article, we will learn how to create a deque of arrays in C++ STL. Example: Input: myArray1 = {1, 4, 8, 9, 11} myArray2 = {1, 2, 3, 2 min read Like