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 first n element.
- If the list contains less than n elements, then the function adds the difference number of elements to the list with their default values.
- The function also accepts a parameter val, if this parameter is specified and the number of elements in the list container is less than n then the function adds elements to the list with their value assigned to val.
list_name.resize(int n, value_type val)
Parameters: This function accepts two parameters as described below.
- n : This parameter specifies the number of elements upto which the list is needed to be resized.
- val: This is an optional parameter and if it is specified and the list contains less than n elements then the function will add elements to the list with their value assigned to val.
Return Value: This function does not return any value.
Below program illustrate the list::resize() function in C++ STL:
Initial List: 10 20 30 40 List after first resize: 10 20 List after second resize: 10 20 0 0 List after third resize: 10 20 0 0 50
- valarray resize() function in C++
- deque resize() function in C++ STL
- forward_list resize() function in C++ STL
- std::string::resize() in C++
- vector : : resize() in C++ STL
- list end() function in C++ STL
- list max_size() function in C++ STL
- list reverse function in C++ STL
- list splice() function in C++ STL
- list merge() function in C++ STL
- list emplace() function in C++ STL
- list back() function in C++ STL
- list empty() function in C++ STL
- list erase() function in C++ STL
- list size() function in C++ STL
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.