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 How to Remove All Occurrences of an Element from Multiset in C++? In C++, a multiset is a container that stores a sorted collection of elements in sorted order, and we can also insert duplicate elements. In this article, we will learn how to remove all the occurrences of a specific element in C++. Example Input: myMultiset = {10, 10, 10, 20, 30, 40}; Target= 10 Ou 2 min read How to Remove an Element from a Deque in C++? 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 A 2 min read How to Remove Last Occurrence of an Element from a Vector in C++? In C++, vectors are the same as dynamic arrays with the ability to resize automatically when an element is inserted or deleted, with their storage being handled automatically by the container. In this article, we will learn how to remove the last occurrence of a specific element in a vector. Input: 2 min read How to Remove Last Element from Vector in C++? Given a vector of n elements, the task is to remove the last element from the vector in C++.The most efficient method to remove the last element from vector is by using vector pop_back() method. Letâs take a look at a simple example:C++#include <bits/stdc++.h> using namespace std; int main() { 2 min read How to Remove an Element from Front of Deque in C++? In C++, a deque (double-ended queue) is a data structure that allows efficient insertion and deletion at both ends. In this article, we will learn to remove an element from the beginning of a deque in C++. Example:Input: myDeque = {1, 2, 3, 4, 5}; Output: Deque After Removal: 2 3 4 5Removing the Fir 2 min read Like