How to Find the Maximum Element in a Deque in C++? Last Updated : 22 Mar, 2024 Comments Improve Suggest changes Like Article Like Report in C++, double-ended queues, also known as deques, are sequence containers with the feature of insertion and deletion on both ends. They are similar to vectors but are more efficient for the insertion and deletion of elements from both ends. In this article, we will learn how to find the maximum element in a deque in C++. Example Input: myDeque = {1,5,3,9,2} Output: Max Element in the Deque is: 9Find the Biggest Element in a Deque in C++ To find the maximum element in a deque in C++, we can use the std::max_element method provided by the STL library of C++. This function returns the biggest element in the given range. Syntax of std::max_element()max_element(first, last); where, first: Iterator pointing to the beginning of the deque.last: Iterator pointing to one position past the end of the deque.C++ Program to Find the Maximum Element in a DequeThe following program illustrates how we can find the biggest number in a deque in C++: C++ // C++ Program to illustrate how to find the maximum element // in a deque #include <algorithm> #include <deque> #include <iostream> using namespace std; int main() { // Initialize a deque deque<int> dq = { 1, 5, 3, 9, 2 }; // Using max_element function to get the iterator to max // element auto maxEle = max_element(dq.begin(), dq.end()); // Print the elements of the deque cout << "Deque Elements: "; for (int x : dq) { cout << x << " "; } // Print the maximum Element by dereferencing the // iterator cout << "\nMax Element in the Deque is: " << *maxEle; return 0; } OutputDeque Elements: 1 5 3 9 2 Max Element in the Deque is: 9Time Complexity: O(N) where N denotes the size of the deque.Auxiliary Space: O(1) Comment More infoAdvertise with us Next Article How to Find the Maximum Element in a Deque in C++? A akshitsaxena2 Follow Improve Article Tags : C++ Programs C++ STL cpp-deque CPP Examples +1 More Practice Tags : CPPSTL Similar Reads How to Find the Minimum Element in a Deque in C++? In C++, a deque (double-ended queue) container is a dynamic array that allows insertions and deletions at both ends. In this article, we will learn how to find the minimum element in a deque in C++. Example: Input: myDeque = {10, 5, 8, 3, 12}; Output: Minimum Element in the Deque: 3Finding the Minim 2 min read How to Find the Maximum Element in a List in C++? In C++, a list is a sequence container provided by the STL library that represents a doubly linked list and allows us to store data in non-contiguous memory locations efficiently. In this article, we will learn how to find the maximum element in a list in C++. Example: Input: myList = {30, 20, 10, 5 2 min read How to Find the Sum of All Elements in a Deque in C++? In C++, double-ended queues are sequence containers similar to vectors but are more efficient in the case of insertion and deletion of elements at both ends. In this article, we will learn how to find the sum of all elements in a deque in C++. Example Input: myDeque ={1,2,3,4,5} Output: Sum of all d 2 min read How to Find the Minimum Element in a List in C++? In C++, a list is a sequence container provided by the STL library that stores data in non-contiguous memory locations efficiently. In this article, we will learn how to find the minimum element in a list in C++. Example: Input: myList = {30, 10, 20, 50, 40};Output: The minimum element in the list i 2 min read How to Find Mode of All Elements in a Deque in C++? In C++, deque is a container provided by the STL library of C++ that allows insertion and deletion from both ends. The mode of a deque represents the element that appears most frequently in the container. In this article, we will learn how to find the mode of all elements in a deque in C++. Example: 2 min read Like