How to Remove an Element from the End of a List in C++? Last Updated : 02 Apr, 2024 Comments Improve Suggest changes Like Article Like Report 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 from a List in C++To remove an element from the end of a std::list in C++, we can use the std::list::pop_back() function that removes the last element from a list in constant time. Syntax of std::list::pop_back()list_name.pop_back()C++ Program to Remove an Element from the End of a ListThe following program illustrates how we can remove an element from the end of a list using the pop_back() method in C++. C++ // C++ Program to how we can remove an element from the end // of a list using the pop_back() method #include <iostream> #include <list> using namespace std; int main() { // Initializing a list list<int> l1 = { 10, 20, 30, 40, 50 }; // Printing the original list cout << "Original List: "; for (int element : l1) { cout << element << " "; } cout << endl; // Removing the last element of the list using pop_back l1.pop_back(); // Printing the list after removing the last element cout << "List after removing the last element: "; for (int element : l1) { cout << element << " "; } return 0; } OutputOriginal List: 10 20 30 40 50 List after removing the last element: 10 20 30 40 Time Complexity: O(1)Auxiliary Space: O(1) Comment More infoAdvertise with us Next Article How to Remove an Element from the End of a List in C++? R rohitshapcxa 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 the End of a Deque in C++? In C++, deque is also called a double-ended queue where we can insert new elements at both the front and back of the container. In this article, we will learn to remove an element from the end of a deque in C++. Example: Input: myDeque = {1, 2, 3, 4, 5} Output: Deque after removal: 1 2 3 4 Removing 2 min read 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 Beginning of List in C++? 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 fr 2 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 Add an Element at the End of List in C++? In C++, the Standard Template Library (STL) has a doubly-linked list container, known as std::list that offers various functions to manipulate elements. In this article, we will learn how to add an element at the end of a list in C++ STL. Example: Input: myList = {1, 2, 3}; Output: List after Elemen 2 min read Like