Signup/Sign In

C++ Using STL Lists (Part 1) Program

Hello Everyone!

In this tutorial, we will learn about the working of Lists (Part 1), in the C++ programming language.

To understand the basic functionality of the Lists in C++, we will recommend you to visit, where we have explained this concept in detail from scratch.

For better understanding of it's implementation, refer to the well commented CPP code given below.


#include <iostream>
#include <bits/stdc++.h>

using namespace std;

//Function to print the elements of the list
void show(list<int> &l)
    //Defining an iterator for the list
    list<int>::iterator i;

    for (i = l.begin(); i != l.end(); i++)
        cout << "\t" << *i;

    cout << endl;

int main()
    cout << "\n\nWelcome to Studytonight :-)\n\n\n";
    cout << " =====  Program to demonstrate the working of Lists (Part 1), in CPP  ===== \n\n";

    int i;

    //List declaration (list of integers)
    list<int> l1, l2;

    //Filling the elements
    cout << "Filling both the lists in two possible ways: from front and from back\n\n";
    for (i = 0; i < 5; i++)
        l1.push_back(i * 10);  //inserting elements from end
        l2.push_front(i * 20); //inserting elements from front

    cout << "List 1 whose element is inserted from end is: ";

    cout << "\n\nList 1 whose element is inserted from front is: ";

    cout << "\n\nThe first element of the list 1 is :  " << l1.front();

    cout << "\n\nThe last element of the list 2 is :  " << l2.back();

    cout << "\n\nAfter deleting the first element of list 1, it becomes: ";

    cout << "\n\nAfter deleting the last element of list 2, it becomes: ";

    cout << "\n\n\n";

    return 0;


C++ Lists Part 1

We hope that this post helped you develop a better understanding of the concept of Lists and its implementation in C++. For any query, feel free to reach out to us via the comments section down below.

Keep Learning : )

About the author:
Nikita Pandey is a talented author and expert in programming languages such as C, C++, and Java. Her writing is informative, engaging, and offers practical insights and tips for programmers at all levels.