![]() |
In C++ STL, we have a container called deque(short for double-ended queue) that allows fast insertion and deletion operations at both the beginning and end. In this article, we will learn how to reverse a deque in C++. Example: Input: myDeque = {1, 2, 3, 4, 5}; Output: Reversed Deque: 5 4 3 2 1 Reverse Deque in C++ STLTo reverse a std::deque in C++, we can use the std::reverse() function from the <algorithm> library that reverses the order of elements in a given range. We need to pass the beginning and end iterators of the deque to this function. Syntax of std::reverse()
Here,
C++ Program to Reverse a DequeThe below example demonstrates how we can reverse a deque in C++.
Output Original Deque: 1 2 3 4 5 Reversed Deque: 5 4 3 2 1 Time Complexity: O(N), here N is the number of elements in deque. |
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 14 |