deque::assign vs deque::at

Below are the differences between deque::assign and deque::at:

Basis deque::assign deque::at
Definition It is used to assign new contents to the deque container, replacing its current contents It is used to return a reference to the element at position n in the deque container object.
Syntax dequename.assign(<int> size, <int> val); reference at (size_type n);
No. Of Parameters It takes two parameters. It takes only one parameter.
Return Value It does not have any return type. Returns a direct reference to the element at the given position.
Complexity Its complexity is linear. Its complexity is constant.


Difference Between deque::assign and deque::at in C++

Deque or Double-ended queues are sequence containers with the feature of expansion and contraction on both ends. They are similar to vectors, but are more efficient in the case of insertion and deletion of elements at the end, and also the beginning. Unlike vectors, contiguous storage allocation may not be guaranteed. Here we will see the difference between deque::assign and deque::at in C++.

Similar Reads

Deque::assign

deque::assign is used to assign new contents to the deque container by replacing its current contents. It modifies the size accordingly....

Deque::at

...

deque::assign vs deque::at

deque::at is used to return a reference to the element at position x in the deque container object. Deque::at automatically checks whether x is within the bounds of valid elements in the container or not....