The Standard Template Library (STL) is a set of C++ template classes to provide common programming data structures and functions such as lists, stacks, arrays, etc. It is a library of container classes, algorithms, and iterators.
STL is mainly composed of:
- Algorithms
- Containers
- Iterators
STL is a generic library , i.e a same container or algorithm
can be operated on any data types.
Algorithms in STL
STL provide number of algorithms that can be used of any container, irrespective of their type. Algorithms library contains built in functions that perform complex algorithms on the data structures.
Example: one can reverse a range with reverse() function, sort a range with sort() function, search in a range with binary_search() and so on.
Algorithm library provides abstraction, i.e you don't necessarily need to know how the the algorithm works.
Containers in STL
Container library in STL provide containers that are used to create data structures like arrays, linked list, trees etc.
These container are generic, they can hold elements of any data types, for example: vector can be used for creating dynamic arrays of char, integer, float and other types.
Iterators in STL
Iterators in STL are used to point to the containers. Iterators actually act as a bridge between containers and algorithms.
Example: sort() algorithm have two parameters,
starting iterator and ending iterator, now sort() compare the elements pointed
by each of these iterators and arrange them in sorted order, thus it does not
matter what is the type of the container and same sort() can be used on
different types of containers.
0 comments:
Post a Comment