Cody  Lindgren

Cody Lindgren


List | C++ STL (Standard Template Library) | std::list

In this lesson we study about list container and different functions of list.
Complete C++ STL playlist:
Github Link:

#stl #list #standardtemplatelibrary #CPP

#stl #list #cpluplus

What is GEEK

Buddha Community

List | C++ STL (Standard Template Library) | std::list
Ari  Bogisich

Ari Bogisich


Standard Template Library (STL) in C++ | Lists

The **Standard Template Library (STL) **is a very useful set of template classes containing various containers. One among these containers is Lists. Today we’ll be having a look at Lists in STL. But before we proceed further I’d like to say that if this is your first time learning STL then I’d recommend you have a look at this article before beginning with this one.

With that being said let’s dive further into the topic by knowing what are lists in STL ?

A. Lists in STL

Lists are a type of sequence containers which provides us with constant insertion and deletion time anywhere within the sequence given that we have obtained the corresponding iterator to the same. It also allows us traversal in both the directions.

List containers are implemented as doubly-linked lists. The memory management is done internally by maintaining a link to the previous as well as the next element in the sequence with respect to each element. A significant drawback of lists being that we don’t have direct access to the elements since it uses non contiguous memory allocation for each element in the sequence. Thus in order to get to a specific element in the sequence one has to iterate through the list which takes linear time. Apart from that it also takes up a bit more extra space when compared to vectors, which it uses to keep track of the links to previous and next elements corresponding to each element in the sequence.

#standard-template-library #lists-in-cplusplus #stl #cplusplus #programming-c

Ari  Bogisich

Ari Bogisich


Standard Template Library (STL) in C++ | Vectors

The Standard Template Library (STL) in C++ is nothing but a set of template classes which provides us with the widely used data structures such as lists, stacks, maps, etc. along with iterators, functions and algorithms in order to play around with the data elements.

A. Main Components of STL


Containers are nothing but holder objects which stores other objects i.e. it’s elements. A container does the memory management for its elements and provides us with member functions or iterators in order to interact with it’s data elements.


Algorithms, defined under the header , are nothing but a collection of several functions which are designed in order to used on any sequence of elements that can be accessed using iterators or pointers. One thing to note about algorithms is that they do not change the way a data structure is organised in any way. They merely deal with the elements within the structure.


Iterators are something which is used to point at the memory addresses of STL containers’ elements. Thus providing a means to access the data stored within the container. They can be simply thought of as pointers. More about them can be read here.

Now with that being said we are good to go ahead and have a look at our very first container Vector.

B. Vectors in STL

We all know about the commonly used data structure, arrays. A vector can be simply thought of as an array with the added functionality that it’s size can vary over time. Thus we can say that vectors are sequence containers representing arrays that can change it’s size dynamically.

Just like an array, a vector too uses contiguous memory allocation for its elements thus we can make use of offsets in order to access the elements of a vector. Internally vectors make use of dynamically allocated arrays. This array may need to be reallocated in order to grow in size thus resulting in a costly operation of reallocation and copying the elements. Thus vectors do not reallocate each time instead they have an extra amount of space which is greater than their actual size (current size of the vector) and re-allocations usually happen at logarithmic intervals. Thus, vectors occupy more space when compared to an array in exchange of dynamic nature and efficient memory management.

C. Let’s have a look at the syntax

We need to import the header  so that we can make use of vectors

#include <vector>

Now, in order to declare a vector we use the following syntax

vector vector_name;

Eg : vector v;

This declares a vector with 0 elements in it.

D. Different ways of vector declaration and initialisation

#include <iostream>
#include <vector>

using namespace std;
int main()
 vector <int> myVec;     // simple declaration
 myVec.assign(10, 33);   // 10 ints with a value of 33

 vector <int> v{1,2,3};  // initialise on the go
 vector <int> v1(3);     // 3 ints with value of 0
 vector <int> v2(3,7);   // 3 ints with value of 7
 return 0;

#vector #standard-template-library #cplusplus #stl #programming-c

Cody  Lindgren

Cody Lindgren


List | C++ STL (Standard Template Library) | std::list

In this lesson we study about list container and different functions of list.
Complete C++ STL playlist:
Github Link:

#stl #list #standardtemplatelibrary #CPP

#stl #list #cpluplus

Shaylee  Lemke

Shaylee Lemke


The numerical algorithms that are found in the Standard Template Library (STL)

In this article I will discuss the numerical algorithms that are found in the Standard Template Library (STL). These algorithms do not replace the math library for the types of functions found in cmath but provide a different set of algorithms for solving certain numerical processing problems.

#c #c# #c++ #programming-c

Hudson  Larkin

Hudson Larkin


C++ List Example | List in C++ Standard Template Library

C++ List is the inbuilt sequence containers that allow non-contiguous memory allocation. The list doesn’t provide fast random access, and it only supports sequential access in both directions. The list is a sequence container available with STL(Standard Template Library) in C++. By default, the list is a doubly-linked list. Since it is a doubly-linked list, the insertion and deletion are fast on the list.

It uses non-contiguous memory allocation, so traversal is slow compared to  vector in C++.

C++ List Example

The list allows insertion and deletion operation anywhere within a sequence in constant time.

Elements of the list can be scattered in the different chunks of memory. Container stores the necessary information to allow sequential access to its data.

C++ Lists can shrink or expand as needed from both ends at run time. The storage requirement is fulfilled automatically by the internal allocator.

Zero-sized lists are also valid. In that case list.begin() and list.end() points to the same location. But the behavior of calling front() or back() is undefined.

#c++ #c++ list