How to Remove an Element from Beginning of List in C++? Last Updated : 26 Mar, 2024 Comments Improve Suggest changes Like Article Like Report 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:myList ={1,2,3,4,5}Output:myList = {2,3,4,5}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++: C++ // C++ program to illustrate how to remove an element from // the beginning of a list #include <iostream> #include <list> using namespace std; int main() { list<int> l = { 1, 2, 3, 4, 5 }; // Print the original list cout << "Original List: "; for (int x : l) { cout << x << " "; } cout << endl; // Remove the first element from the list l.pop_front(); // Print the modified list cout << "Updated List: "; for (int x : l) { cout << x << " "; } return 0; } OutputOriginal List: 1 2 3 4 5 Updated List: 2 3 4 5 Time Complexity: O(1) Auxiliary Space: O(1) Comment More infoAdvertise with us Next Article How to Remove an Element from Beginning of List in C++? R rajputabbhy4 Follow Improve Article Tags : C++ Programs C++ STL cpp-list CPP Examples +1 More Practice Tags : CPPSTL Similar Reads How to Remove an Element from a List in C++? In C++, the STL provides a std::list container that represents a doubly linked list to store the sequential data in non-contiguous memory locations. In this article, we will learn how to remove an element from a list in C++. Example: Input: myList = {1, 2, 3, 4, 5, 6, 7, 8} Target = 5 Output: // rem 2 min read How to Remove an Element from the End of a List in C++? In C++, lists are data structures that allow us to store data of the same type in non-contiguous memory locations. In this article, we will learn how to remove an element from the end of a list in C++. Example Input: myList={10,20,30,40,50} Output: List Elements: 10 20 30 40Delete the Last Element f 2 min read How to Remove All Occurrences of an Element from List in C++? In C++, Lists are sequence containers that allow non-contiguous memory allocation. In this article, we will learn how to remove an element from a list in C++. Example Input: myList = {100, 78, 120, 12, 56, 78, 78}target = 78Output:// Removed element 78 from the list{ 100, 120, 12, 56}Remove an Eleme 2 min read How to Remove an Element from Array in C++? In C++, removing an element from an array is tricky because we cannot modify the memory space occupied by the array. So, we pseudo delete the element by moving it to the end of the array and reducing the size. In this article, we will learn how to remove a value from an array in C++.ExamplesInput: a 3 min read How to Remove an Element from a Set in C++? In C++, sets are a type of associative container in which each element has to be unique. The values are stored in a specific sorted order i.e. either ascending or descending. In this article, we will see how to remove specific elements from a set in C++. Example Input: set = {100,120,12,56,78,9,32,4 2 min read Like