List in STL - C++

Hello coders, welcome you all to learn std::list.If you think that your list concept is not upto the par or you want to improve your list knowledge, then you have come to right place. Let’s dive into to the pool of list ,


● List is a sequence container that allows storing elements at a separate memory location (i.e. known as a node) and also it contains two pointers that are pointing the next and the previous node .

● std::list is internally implemented as a doubly-linked list.

● Insertion and deletion operation can be performed on the lists in constant time.

To use the std::list it is important to add <list> header file in your program.

Let’s write some code to create and insert the elements at the front and back of a list.


Content of list l :

Content of list l1 : 1 2 3 4 5

Content of list l2 : 0 0 0 0 0

Content of list l3 : 10 10 10 10 10

Below is the program to show the working of some functions of List:


Size of l: 0

Size of l1: 5

Does list l is empty : 1

Does list l1 is empty : 0

Content of list l : 2 2

Content of list l1 : 1 2 3 4 5

First element of list l is 2

First element of list l1 is 4

Last element of list l is 2

Last element of list l1 is 5

Content of list l : 2

Content of list l1 : 4 5

So that’s it for this article we will be coming up with our next article very soon till then keep learning, keep coding, keep reading and keep improving !!

Happy Coding 😊

By Programmers Army