Javatpoint Logo
Javatpoint Logo

C++ Deque resize()

C++ Deque resize() function changes the size of the deque container to the size given in the argument.

Following are the conditions:

If n is greater than the container size then the container size is extended to n elements by inserting new elements at the extended space.

If n is smaller than the container size then the container is reduced to n elements and removing all the elements beyond n element.

Where, n is a new size of the container given in the argument.

Syntax

Parameter

n: It is a new container size.

val: New value to be added in the extended space.

Return value

It does not return any value.

Example 1

Let's see a simple example when n is less than the container size.

Output:

100 200 300 

In this example, resize() function resizes the container size to 3. Therefore, all the elements beyond the 3rd element are removed.

Example 2

Let's see a simple example when n is greater than the container size.

Output:

C C++ java .Net python rust rust 

In this example, resize() function resizes the container size to 7. Therefore, newly added space is inserted with a new element i."rust".


Next TopicC++ Deque



Please Share

facebook twitter google plus pinterest