How to Create Deque of User-Defined Data Type in C++? Last Updated : 26 Mar, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report In C++, deque is a container in which we can insert and delete at both its beginning and its end. It supports almost all kinds of inbuilt data types. In this article, we will learn how to create a deque of user-defined data types in C++. Example Input://user defined data typestruct usd { int a; char b;};Output:Elements in the Stack of usd:(1, 'c')(1, 'd')Create a Deque of User-Defined Data Type in C++ If our user defined data type is copy constructible and assignable, we can create a std::deque of user-defined data type by passing that type as the template parameter in the deque declaration. Syntax: deque<DataType> dq_Name;C++ Program to Create a Deque of User-Defined Data TypeThe following program illustrates how we can create a deque of user-defined data type in C++: C++ // C++ program to illustrate how to create a deque of // user-defined data type #include <deque> #include <iostream> #include <string> using namespace std; // Define the user-defined data type class Person { public: string name; int age; Person(string name, int age) { this->name = name; this->age = age; } }; int main() { // Creating a deque of user-defined data type deque<Person> dq; // Create Person objects Person p1("John", 30); Person p2("Steve", 40); Person p3("David", 50); Person p4("Alice", 60); // Insert the Person objects to the deque dq.push_back(p1); dq.push_back(p2); dq.push_back(p3); dq.push_back(p4); // Print the deque elements cout << " Deque Elements: " << endl; for (Person& p : dq) { cout << "{ Name: " << p.name << ", Age: " << p.age << " }" << endl; } return 0; } Output Deque Elements: { Name: John, Age: 30 } { Name: Steve, Age: 40 } { Name: David, Age: 50 } { Name: Alice, Age: 60 } Time Complexity: O(N) where N is the number of elements in the deque.Auxiliary Space: O(N) Comment More infoAdvertise with us Next Article How to Create a Deque of Vectors 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 Create a Stack of User-Defined Data Type in C++? In C++, we have a stack data structure that follows the LIFO (Last In First Out) rule and allows operations such as push, pop, and top at one end of the structure. In this article, we will learn how to create a stack of user-defined data types in C++. Example: Input://user defined data typestruct Po 2 min read How to Create Deque of Unordered_Set in C++? In C++, a deque (double-ended queue) is a container that allows insertion and removal of elements from both ends whereas an unordered set is a container that stores unique elements in no particular order. In this article, we will learn how to create a deque of unordered sets in C++ STL. Example:Inpu 2 min read How to Create a Deque of Vectors in C++? In C++, deques are sequence containers similar to queues but unlike queues, deques allow the insertion and deletion of elements from both ends efficiently. Vectors are dynamic arrays that can resize themselves during the runtime. In this article, we will learn how to create a deque of vectors in C++ 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 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 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 Like