Skip to content
Related Articles

Related Articles

deque max_size() function in C++ STL

View Discussion
Improve Article
Save Article
  • Last Updated : 20 Jun, 2022
View Discussion
Improve Article
Save Article

The deque::max_size() is a built-in function in C++ STL which returns the maximum number of elements that a deque container can hold. Syntax:

deque_name.max_size()

Parameters: The function does not accept any parameters. Return Value: The function returns the maximum number of elements that a deque container can hold. Below programs illustrate the above function: Program 1: 

CPP




// CPP program to demonstrate the
// deque::max_size() function
// when deque is non-empty
#include <bits/stdc++.h>
using namespace std;
int main()
{
    deque<int> dq;
 
    dq.push_back(1);
    dq.push_back(10);
    dq.push_back(100);
    dq.push_back(50);
    dq.push_back(40);
    dq.push_back(23);
    dq.push_back(6);
 
    cout << "The deque elements: ";
    for (auto it = dq.begin(); it != dq.end(); it++)
        cout << *it << " ";
 
    cout << "\nThe max-size of deque: " << dq.max_size();
 
    return 0;
}

Output:

The deque elements: 1 10 100 50 40 23 6 
The max-size of deque: 4611686018427387903

Program 2: 

CPP




// CPP program to demonstrate the
// deque::max_size() function
// when deque is empty
#include <bits/stdc++.h>
using namespace std;
int main()
{
    deque<int> dq;
 
    cout << "The max-size of deque: " << dq.max_size();
 
    return 0;
}

Output:

The max-size of deque: 4611686018427387903

Time complexity: O(1)

Auxiliary Space: O(1)


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!