deque resize() function in C++ STL Last Updated : 30 Aug, 2018 Comments Improve Suggest changes Like Article Like Report The deque::resize() is an inbuilt function in C++ STL which changes the size of the deque. If the given size is greater than the current size, then new elements are inserted at the end of the deque. If the given size is smaller than the current size, then extra elements are destroyed. Syntax: deque_name.resize(n) Parameter: The function accepts only one mandatory parameter n which specifies the size of the deque. Return value: The function does not return anything. Below program illustrates the above function: Program 1: CPP // C++ program to illustrate the // deque::resize() function #include <bits/stdc++.h> using namespace std; int main() { deque<int> dq = { 10, 20, 30, 40, 50 }; cout << "Size before resize " << dq.size() << "\n"; // Prints the deque elements cout << "The contents of deque :"; for (auto it = dq.begin(); it != dq.end(); ++it) cout << *it << " "; cout << endl; // resize to 7 dq.resize(7); // // Prints the deque elements after resize() cout << "Size after resize " << dq.size() << "\n"; cout << "The contents of deque :"; for (auto it = dq.begin(); it != dq.end(); ++it) cout << *it << " "; return 0; } Output: Size before resize 5 The contents of deque :10 20 30 40 50 Size after resize 7 The contents of deque :10 20 30 40 50 0 0 Program 2: CPP // C++ program to illustrate the // deque::resize() function #include <bits/stdc++.h> using namespace std; int main() { deque<int> dq = { 10, 20, 30, 40, 50 }; cout << "Size before resize " << dq.size() << "\n"; // Prints the deque elements cout << "The contents of deque :"; for (auto it = dq.begin(); it != dq.end(); ++it) cout << *it << " "; cout << endl; // resize to 3 dq.resize(3); cout << "Size after resize " << dq.size() << "\n"; cout << "The contents of deque :"; for (auto it = dq.begin(); it != dq.end(); ++it) cout << *it << " "; return 0; } Output: Size before resize 5 The contents of deque :10 20 30 40 50 Size after resize 3 The contents of deque :10 20 30 Time Complexity: O(N) Comment More infoAdvertise with us Next Article list max_size() function in C++ STL R rupesh_rao Follow Improve Article Tags : Misc C++ STL CPP-Functions cpp-deque +1 More Practice Tags : CPPMiscSTL Similar Reads deque max_size() function in C++ STL 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 c 1 min read list resize() function in C++ STL The list::resize() is a built-in function in C++ STL which is used to resize a list container. It takes a number n as parameter and resizes the list container to contain exactly n elements. If the list already has more than n elements, then the function erases the elements from the list except the f 2 min read list size() function in C++ STL The list::size() is a built-in function in C++ STL that is used to find the number of elements present in a list container. That is, it is used to find the size of the list container.Syntax: list_name.size(); Time Complexity - Linear O(1) as per c++11 standard. Possible because the implementation ma 1 min read set max_size() function in C++ STL The set::max_size() is a built-in function in C++ STL which returns the maximum number of elements a set container can hold. Syntax: set_name.max_size() Parameters: This function does not accept any parameters. Return Value: This function returns the maximum number of elements a set container can ho 1 min read list max_size() function in C++ STL The list::max_size() is a built-in function in C++ STL which returns the maximum number of elements a list container can hold. Syntax: list_name.max_size()Parameters: This function does not accept any parameters. Return Value: This function returns the maximum number of elements a list container can 1 min read smatch max_size() function in C++ STL The smatch::max_size() is a built-in function in C++ STL which returns the maximum number of elements in the match_results object that can be held by the smatch container. Syntax: smatch_name.max_size() Parameters: This function does not accept any parameters. Return value: This function returns the 1 min read Like