Home C C++ Java Python Perl PHP SQL JavaScript Linux Selenium QT Online Test

Home » Solved Programs on C++ » STL Container - List's example in C++

STL Container - List example in C++

#include <iostream>
#include <list>

using namespace std;

void addElement(list &, int);
void display_list(list &, string);
void deleteEndsElement(list &);
void reverseList(list &);

int main(int argc, char** argv) {
list listContainer;
addElement(listContainer, 0);
addElement(listContainer, 10);
addElement(listContainer, 20);
addElement(listContainer, 30);
addElement(listContainer, 40);
addElement(listContainer, 50);
addElement(listContainer, 60);
addElement(listContainer, 70);
addElement(listContainer, 80);
addElement(listContainer, 90);

display_list(listContainer, "The orignial list is:");

addElement(listContainer, 5);
addElement(listContainer, 15);
addElement(listContainer, 25);
addElement(listContainer, 35);
addElement(listContainer, 45);
addElement(listContainer, 55);
addElement(listContainer, 65);
addElement(listContainer, 75);
addElement(listContainer, 85);

display_list(listContainer, "The list with the additional numbers is:");
display_list(listContainer, "The list in reverse is:");

display_list(listContainer, "The list with ends removed:");

return 0;

void addElement(list &myList, int no){

void display_list(list &myList, string msg){
cout<<"\n"<::const_iterator ci = myList.begin(); ci != myList.end(); ++ci)
cout << *ci << " ";

cout<<"\nThe number of  list nodes is: "< &myList){
void reverseList(list &myList){

Output of C++ List program

C++ example of List Container

Other Categories

MCQ on C Programming MCQ on C++ Programming 138+C++ F2F Interview Questions Basic Computer Questions Solved C programs Solved C++ programs