![]() |
In C++ STL, a container called deque (known as a double-ended queue) allows us to insert and delete elements at both its beginning and its end. In this article, we will learn how to remove a specific element from a deque in C++ STL. Example: Input: myDeque= {4, 2, 3, 5, 2} Target = 4 Output: Deque After Removal of Target = 2 3 5 2 Erase a Specific Element from a Deque in C++To remove a specific element from a deque in C++, we can use a combination of std::find() and the std::deque:: If the element is at either of the end, the std::deque::erase() function is optimized for the fast removal as well. C++ Program to Remove a Specific Element from a DequeThe below example demonstrates how we can remove a specific element from a deque in C++ STL.
Output Deque after removal: 2 3 5 2 Time Complexity: O(N), here N is the number of elements in the deque |
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 14 |