deque_max_size( ) in C++ in STL

C++Server Side ProgrammingProgramming

Given is the task to show the functionality of deque max_size( ) function in C++ STL.

What is Deque?

Deque is the Double Ended Queues that are the sequence containers which provides the functionality of expansion and contraction on both the ends. A queue data structure allow user to insert data only at the END and delete data from the FRONT. Let’s take the analogy of queues at bus stops where the person can be inserted to a queue from the END only and the person standing in the FRONT is the first to be removed whereas in Double ended queue the insertion and deletion of data is possible at both the ends.

What is deque max_size( ) function?

This function is used to check the maximum number of elements that deque holds.

Syntax: dequename.max_size( )

Returns− It returns the maximum no. of elements that deque holds.

Example

Input Deque: 12 13 14 15 16
Output Maximum size: 4611686018427387903
Input Deque: F O R C E
Output Maximum size: 4611686018427387903

Approach can be followed

• First we declare the deque.

• Then we print the deque.

• Then we check the maximum size of deque.

By using above approach we can check the maximum size of deque.

Example

// C++ code to demonstrate the working of deque max_size( ) function
#include<iostream.h>
#include<deque.h>
Using namespace std;
int main ( ){
// initializing the deque
Deque<int> deque = { 11, 12, 13, 14, 15 };
// print the deque
cout<< “ Deque: “;
for( auto x = deque.begin( ); x != deque.end( ); ++x)
cout<< *x << “ “;
cout<< “ The maximum size of deque: “<< deque.max_size( );
return 0;
}

Output

If we run the above code then it will generate the following output

Input - Deque: 11 12 13 14 15
Output - The maximum size of deque: 461168601842738790

Example

// C++ code to demonstrate the working of deque max_size( ) function
#include<iostream.h>
#include<deque.h>
Using namespace std;
int main( ){
// initializing deque
deque<int> deque ={ 14, 15, 16, 17, 18, 19, 20 };
// print the deque
cout<< “ Deque: “;
for( auto x = deque.begin( ); x != deque.end( ); ++x)
cout<< *x << “ “;
cout<< “Maximum size of deque:” << deque.max_size( );
return 0;
}

Output

If we run the above code then it will generate the following output.

Input: Deque:14 15 16 17 18 19 20
Output: Maximum size of deque: 4611686018427387903
Published on 05-Mar-2020 09:32:50