![]() |
VOOZH | about |
In C++, a deque is a flexible data structure that supports the insertion and deletion of elements from both ends efficiently. In this article, we will learn how to add an element at the end of a deque in C++.
Example:
Input: myDeque ={10,20,30,40} Output:// added element 50 at the end myDeque ={10,20,30,40,50}
To add an element at the end of a std::deque in C++, we can use the deque::push_back() method. This method takes the element to be inserted as an argument and inserts it to the end of the deque.
deque_name.push_back(value);The following program illustrates how we can add an element at the end of a deque in C++:
Original Deque: 10 20 30 40 Updated Deque: 10 20 30 40 50
Time Complexity: O(1)
Auxiliary Space: O(1)