How to Find the Size of a Deque in C++?
Last Updated :
02 Apr, 2024
In C++, deque also known as double-ended queues are containers that allow efficient insertion and deletion operations from both ends of the deque. In this article, we will learn how to find the size of a deque in C++.
Example:
Input:
myDeque = {10, 20, 30, 40, 50}
Output:
Size of the Deque is: 5
Find the Size of a Deque in C++
In C++, the std::deque container keeps track of its size. We can simply use the std::deque::size()
member function of the std::deque
class to get the size of the deque container. It returns the size i.e., the number of elements present in the deque in the form of an integer.
Syntax of std::deque::size()
dq_name.size()
C++ Program to Find the Size of a Deque
The below program demonstrates how we can find the size of a deque in C++.
C++
// C++ Program to demonstrate how we can find the size of a
// deque
#include <deque>
#include <iostream>
using namespace std;
int main()
{
// Initializing a deque
deque<int> dq = { 10, 20, 30, 40, 50 };
// Finding the size of the deque
int dequeSize = dq.size();
// Printing the size of the deque
cout << "Size of the Deque is: " << dequeSize << endl;
return 0;
}
OutputSize of the Deque is: 5
Time Complexity: O(1)
Auxiliary Space: O(1)
Share your thoughts in the comments
Please Login to comment...