Introduction to STL: Containers, Algorithms, iterators – potential problems with STL| OOP in C++


Standard Template Library


The collection of genetic classes and functions is called Standard Template Library(STL).
Components of STL
(A) Containers
(B) Algorithms
(C) Iterators
STL
Container is an object that actually stores data STL containers are implemented by template classes and therefore can be used with different data types. Example-Array(integer array, char array, float array)
ALGORITHM is a procedure that is used to process data present in container. Algorithms are implemented using template function.

The following tasks can be done using algorithms: Initialization, Searching, Sorting, Copying, Merging.etc.

Iterator is an object, like a pointer, that points to an element in a container one can increment/decrement iterators.
Iterator connects algorithm with containers
Type of Containers in STL
1. Sequence Container
-vector
-list
-deque
2. Associative Container
-set
-multi-set
-map
-multi-map
3. Derived Container
-stack
-queue
-priority queue

stl1
stl containers
 Note:- Derived containers like stack, queue, priority queue do not support iterators, however they support two member functions, push() and pop().

Algorithm
Algorithms are not member function or friend function of any class. They are stand alone template functions.
Type of STL Algorithms
1. Retrieve or Non-mutating
2. Mutating
3. Sorting
4. Set
5. Relational

Custom Search

%d bloggers like this: