![]() |
In C++, lists are sequence containers provided by the STL library, that allow the users to store data in non-contiguous memory locations. Lists are similar to vectors but lists allow constant time insert and delete operations from both ends. In this article, we will learn how to remove an element from the beginning of a list in C++. Example Input: Remove an Element from Beginning of List in C++To remove an element from the beginning of a std::list in C++, the simplest way is to use the std::list::pop_front() method provided by the list container. This function removes the first element of the list in constant time. Syntaxlist_name.pop_front() C++ Program to Remove an Element from the Beginning of a ListThe following program illustrates how we can remove an element from the beginning of a list in C++:
Output Original List: 1 2 3 4 5 Updated List: 2 3 4 5 Time Complexity: O(1) |
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 13 |