Main menu

Pages

C++ STL Classes - Learn CPP(STL) in the programming language (C++) is an abbreviation for (Standard Template Library), which is a huge library that contains a set of ready-made functions and classes, which are used to store a set of values in a very easy way, which makes dealing with them It is very easy in terms of adding elements in it, deleting elements from it, updating its element values, arranging its elements and searching in it, and it contains a set of components:


  • Containers.
  • Algorithms.
  • Functions.
  • Sequences (Iterators).

C++ STL Classes - Learn CPP



The main classes of dynamic containers in C++


Sequence Containers


It is the container that stores the elements that we add in it sequentially behind each other, giving each element a number called (Index) as if it were an ordinary array.


Associative Containers


It is the container that stores the items we add to it in the form of a table, as each item we add in it contains a Key and a Value.


Container Adapters


It is the container that stores the elements added by the user sequentially with the ability to access them, according to the order in which they were entered in (FIFO) or (LIFO) style, or according to the priority given to their elements.


Unordered Associative Containers


It is the container that stores the items added by the user in the form of (buckets), which makes the process of accessing them very fast.


What is the difference between a regular array and a dynamic container?


In the case of creating ordinary arrays, the user must specify the number of its elements at the moment of its creation so that a fixed space is reserved for it in memory and after that, it is dealt with. The allocated space is deleted, which makes the program execution process faster.


In a normal array, its elements are handled only by the element number (Index), while in dynamic containers there are many functions that we use to deal with the elements.


The main classes in STL in the C++ programming language


array


This class is used to create an object that represents a sophisticated array compared to the normal array, as it is more flexible to deal with because the user can know the number of its elements and get the value of the first and last element in it with ease.


vector


This class is used to create an object that represents a container in which the items added by the user are stored sequentially, giving each item an index number. This class is somewhat similar to an ordinary array, but the main difference between them is that its size is not fixed.


forward_list


This class is used to create an object that represents a container in which we store the items in sequence, giving each of them the address of the next in memory so that the order in which the storage process is carried out is preserved.


list


This class is used to create an object that represents a container that stores the elements added by the user in sequence, giving each element the address of the element that precedes it and the address of the element that follows it in memory so that the order in which they are stored is preserved and to be able to move between the elements in both directions from the first element to the other And quite the opposite.


stack


This class is used to create an object that is a container used to store the items added by the user sequentially in a method (LIFO) which means that the item that enters first comes out last.


queue


This class is used to create an object that is a container where the user-added items are stored sequentially behind each other in a FIFO fashion, which means that the first in first out.


priority_queue


This class is used to create an object that represents a container that stores the items added by the user in a specific order, with the item with the largest value being placed at the beginning and the item with the smallest value at the end, plus it allows you to access the highest and lowest value.


deque


This class is used to create an object that represents a container that stores the items added by the user sequentially giving each item a number (Index), which makes the user able to access all its items and add new items anywhere in it.


set


This class is used to create an object that represents a container in which items are stored sequentially and in a certain order, where the item with the smallest value is placed at the beginning, and the item with the largest value is placed at the end or vice versa, in addition, it is not possible to store duplicate values ​​in it


multiset


This class is used to create an object that represents a container that stores items sequentially and in a certain order, where the element with the smallest value is placed at the beginning and the element with the largest value is placed at the end or vice versa and no duplicate values ​​can be stored in it.


map


It is used to create an object that represents a container that stores the items we add to it in the form of a two-column table where each item consists of a key placed in the first column and a value placed in the second column in addition to providing the ability to arrange items in ascending order according to the values ​​of the keys.


multimap


This class is used to create an object that represents a container that stores the items added by the user in the form of a table consisting of two columns, where each item consists of a key placed in the first column and a value (Value) placed in the second column. Noting that the same key can be placed for more than one element.


unordered_set


This class is used to create an object that represents a container that stores the elements added by the user in a specific order, which is determined by a custom function called (Hash) which checks the values ​​of any element to be entered to determine where it should be placed.


unordered_multiset


This class is used to create an object representing a container that stores the elements in a specific order that is specified by a custom function called (Hash) where it checks the values ​​of any element to be entered to determine where it should be placed with the indication that duplicate values ​​can be stored inside it.


unordered_map


It is used to create an object that represents a container that stores the items that we add in it in the form of a table consisting of two columns, where each element consists of a key placed in the first column and a value placed in the second column in addition to that it arranges the elements based on a custom function called Hash. ) checks on the key of any item to be entered to determine where it should be placed.


unordered_multimap


This class is used to create an object that represents a container that stores items in the form of a table consisting of two columns. Hash() where you check the key of any element to be entered to determine where it should be placed, indicating that the same key can be placed in more than one element.