![]() |
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} Add an Element at the Back of a Deque in C++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. Syntax:deque_name.push_back(value); C++ Program to Add an Element at the End of a DequeThe following program illustrates how we can add an element at the end of a deque in C++:
Output Original Deque: 10 20 30 40 Updated Deque: 10 20 30 40 50 Time Complexity: O(1) |
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 11 |