Open In App
Related Articles

deque max_size() function in C++ STL

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

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)



Last Updated : 27 Jun, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads